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
27mod app;
28pub use app::AppExt;
29
30pub mod block;
31pub mod doc;
32pub mod edit;
33pub mod find;
34pub mod highlight;
35pub mod layout;
36pub mod link;
37pub mod marks;
38#[cfg(feature = "mermaid")]
39pub mod mermaid;
40pub mod parse;
41pub mod preview;
42pub mod quote;
43pub mod render;
44pub mod select;
45pub mod selectable;
46pub mod serialize;
47pub mod source;
48pub mod source_style;
49pub mod typography;
50
51pub use block::{BlockRenderer, Fence, Rewrite};
52pub use doc::{Align, Block, BlockKind, Doc, Form, Mark, MarkSpan, Part, QuoteKind, Text};
53pub use edit::{Shortcut, Splice, shortcut};
54pub use find::{FindPaint, default_find};
55pub use highlight::Highlighter;
56pub use layout::Layout;
57pub use link::LinkHandler;
58pub use marks::{
59    HighlightColor, HighlightPaint, MarkPaint, Marks, default_highlight, highlight_solid,
60};
61pub use parse::{
62    ParsedDoc, is_image, is_link, is_url, parse, parse_at, parse_at_many, parse_ranges, parse_with,
63};
64pub use preview::{LinkCard, LinkPreview, Preview};
65pub use quote::Quote;
66pub use render::{
67    Annotation, BlockLayouts, Caption, CopyButton, Editing, FenceHost, ImageOverlay,
68    ImageOverlayCorner, LeaveBlock, OnImage, OnLeave, OnResize, OnRewrite, OnToggle,
69    PAINTED_CONTEXT, RevealMode, Toggle, image_source, markdown, render, render_source,
70    render_with,
71};
72pub use select::{Cursor, Selection};
73pub use serialize::{serialize, serialize_at, serialize_at_many, serialize_with};
74pub use source::spans as source_spans;
75pub use source_style::SourceStyle;
76pub use typography::Typography;