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::QuoteKind;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 layout::Layout;pub use layout::set_layout;pub use marks::MarkPaint;pub use marks::Marks;pub use marks::set_mark_paint;pub use marks::set_marks;pub use parse::ParsedDoc;pub use parse::is_image;pub use parse::is_url;pub use parse::parse;pub use parse::parse_at;pub use parse::parse_ranges;pub use parse::parse_with;pub use preview::LinkPreview;pub use preview::Preview;pub use preview::set_link_preview;pub use render::Annotation;pub use render::BlockLayouts;pub use render::Caption;pub use render::CopyButton;pub use render::Editing;pub use render::OnToggle;pub use render::Toggle;pub use render::markdown;pub use render::render;pub use render::render_source;pub use render::render_with;pub use select::Cursor;pub use select::Selection;pub use serialize::serialize;pub use serialize::serialize_at;pub use serialize::serialize_with;pub use source::spans as source_spans;pub use source_style::SourceStyle;pub use source_style::set_source_style;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.
- layout
- How a document breaks its lines.
- marks
- The inline marks an app spells itself.
- 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.- source
- Colouring markdown source.
- source_
style - Host styling for the plain-text source view.
- typography
- What a document is set in.