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 parse;
32pub mod preview;
33pub mod render;
34pub mod select;
35pub mod serialize;
36pub mod typography;
37
38pub use block::{BlockRenderer, set_block_renderer};
39pub use doc::{Align, Block, BlockKind, Doc, Form, Mark, MarkSpan, Part, Text};
40pub use edit::{Shortcut, Splice, shortcut};
41pub use highlight::{Highlighter, languages, set_highlighter};
42pub use parse::{is_image, is_url, parse};
43pub use preview::{LinkPreview, Preview, set_link_preview};
44pub use render::{Annotation, BlockLayouts, Caption, Editing, markdown, render, render_with};
45pub use select::{Cursor, Selection};
46pub use serialize::serialize;
47pub use typography::{Typography, set_typography};