markdown/lib.rs
1//! A Notion-style block document model, with markdown as the wire form.
2//!
3//! ```
4//! let doc = markdown::parse("# Title\n\n- a\n- b");
5//! assert_eq!(doc.blocks.len(), 3);
6//! assert_eq!(markdown::serialize(&doc), "# Title\n\n- a\n- b");
7//! ```
8//!
9//! The model is a flat list of blocks with an indent level ([`Doc`]), not a
10//! nested tree — Notion's shape rather than CommonMark's, chosen because
11//! editing a flat list is list operations while editing a tree is restructuring.
12//! [`parse`] and [`serialize`] are inverses up to a fixed point: parsing,
13//! serializing and parsing again always lands on the same document, so an
14//! edit/save cycle cannot drift.
15//!
16//! [`doc`], [`parse`], [`serialize`], [`select`] and [`edit`] are pure — no
17//! gpui, no painting — and [`render`] is the gpui layer over them, caret and
18//! selection included for a caller that owns them. The editing *surface* is the
19//! `editor` crate.
20//!
21//! An image at an `http` URL — a picture, a favicon, a bookmark's cover —
22//! needs an http client on the app, which `gpui_platform::application` installs
23//! and a hand-built [`gpui::Application`] does not. gpui's own default is a
24//! `NullHttpClient`, and the failure is silent: the element paints the same
25//! fallback it would show while a fetch was still in flight.
26
27pub mod block;
28pub mod doc;
29pub mod edit;
30pub mod highlight;
31pub mod layout;
32pub mod marks;
33pub mod parse;
34pub mod preview;
35pub mod render;
36pub mod select;
37pub mod selectable;
38pub mod serialize;
39pub mod source;
40pub mod source_style;
41pub mod typography;
42
43pub use block::{BlockRenderer, set_block_renderer};
44pub use doc::{Align, Block, BlockKind, Doc, Form, Mark, MarkSpan, Part, QuoteKind, Text};
45pub use edit::{Shortcut, Splice, shortcut};
46pub use highlight::{Highlighter, languages, set_highlighter};
47pub use layout::{Layout, set_layout};
48pub use marks::{MarkPaint, Marks, set_mark_paint, set_marks};
49pub use parse::{is_image, is_url, parse, parse_at, parse_with};
50pub use preview::{LinkPreview, Preview, set_link_preview};
51pub use render::{
52 Annotation, BlockLayouts, Caption, Editing, markdown, render, render_source, render_with,
53};
54pub use select::{Cursor, Selection};
55pub use serialize::{serialize, serialize_at, serialize_with};
56pub use source::spans as source_spans;
57pub use source_style::{SourceStyle, set_source_style};
58pub use typography::{Typography, set_typography};