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