Skip to main content

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 doc;
28pub mod edit;
29pub mod highlight;
30pub mod parse;
31pub mod preview;
32pub mod render;
33pub mod select;
34pub mod serialize;
35
36pub use doc::{Align, Block, BlockKind, Doc, Form, Mark, MarkSpan, Part, Text};
37pub use edit::{Shortcut, shortcut};
38pub use highlight::{Highlighter, languages, set_highlighter};
39pub use parse::{is_image, is_url, parse};
40pub use preview::{LinkPreview, Preview, set_link_preview};
41pub use render::{BlockLayouts, Caption, markdown, render, render_with_selection};
42pub use select::{Cursor, Selection};
43pub use serialize::serialize;