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