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;
38pub mod parse;
39pub mod preview;
40pub mod quote;
41pub mod render;
42pub mod select;
43pub mod selectable;
44pub mod serialize;
45pub mod source;
46pub mod source_style;
47pub mod typography;
48
49pub use block::BlockRenderer;
50pub use doc::{Align, Block, BlockKind, Doc, Form, Mark, MarkSpan, Part, QuoteKind, Text};
51pub use edit::{Shortcut, Splice, shortcut};
52pub use find::{FindPaint, default_find};
53pub use highlight::Highlighter;
54pub use layout::Layout;
55pub use link::LinkHandler;
56pub use marks::{
57    HighlightColor, HighlightPaint, MarkPaint, Marks, default_highlight, highlight_solid,
58};
59pub use parse::{ParsedDoc, is_image, is_url, parse, parse_at, parse_ranges, parse_with};
60pub use preview::{LinkPreview, Preview};
61pub use quote::Quote;
62pub use render::{
63    Annotation, BlockLayouts, Caption, CopyButton, Editing, ImageOverlay, ImageOverlayCorner,
64    OnImage, OnToggle, Toggle, image_source, markdown, render, render_source, render_with,
65};
66pub use select::{Cursor, Selection};
67pub use serialize::{serialize, serialize_at, serialize_with};
68pub use source::spans as source_spans;
69pub use source_style::SourceStyle;
70pub use typography::Typography;