Skip to main content

Crate markdown

Crate markdown 

Source
Expand description

A Notion-style block document model, with markdown as the wire form.

let doc = markdown::parse("# Title\n\n- a\n- b");
assert_eq!(doc.blocks.len(), 3);
assert_eq!(markdown::serialize(&doc), "# Title\n\n- a\n- b");

The model is a flat list of blocks with an indent level (Doc), not a nested tree — Notion’s shape rather than CommonMark’s, chosen because editing a flat list is list operations while editing a tree is restructuring. [parse] and [serialize] are inverses up to a fixed point: parsing, serializing and parsing again always lands on the same document, so an edit/save cycle cannot drift.

doc, [parse], [serialize], select and edit are pure — no gpui, no painting — and [render] is the gpui layer over them, caret and selection included for a caller that owns them. The editing surface is the editor crate.

An image at an http URL — a picture, a favicon, a bookmark’s cover — needs an http client on the app, which gpui_platform::application installs and a hand-built gpui::Application does not. gpui’s own default is a NullHttpClient, and the failure is silent: the element paints the same fallback it would show while a fetch was still in flight.

Re-exports§

pub use block::BlockRenderer;
pub use block::set_block_renderer;
pub use doc::Align;
pub use doc::Block;
pub use doc::BlockKind;
pub use doc::Doc;
pub use doc::Form;
pub use doc::Mark;
pub use doc::MarkSpan;
pub use doc::Part;
pub use doc::Text;
pub use edit::Shortcut;
pub use edit::Splice;
pub use edit::shortcut;
pub use highlight::Highlighter;
pub use highlight::languages;
pub use highlight::set_highlighter;
pub use parse::is_image;
pub use parse::is_url;
pub use parse::parse;
pub use preview::LinkPreview;
pub use preview::Preview;
pub use render::Annotation;
pub use render::BlockLayouts;
pub use render::Caption;
pub use render::Editing;
pub use render::markdown;
pub use render::render;
pub use render::render_with;
pub use select::Cursor;
pub use select::Selection;
pub use serialize::serialize;
pub use typography::Typography;
pub use typography::set_typography;

Modules§

block
Who paints a fenced block.
doc
The document model.
edit
Editing a Doc.
highlight
Who colors a fenced block.
parse
Markdown → Doc.
preview
Who describes a link.
render
Doc → gpui elements.
select
Positions and ranges in a Doc.
selectable
Text you can select with the pointer and copy out of.
serialize
Doc → markdown.
typography
What a document is set in.