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//! Everything that paints is behind the `gpui` feature, on by default. Without
22//! it the crate is the document model alone and builds for
23//! `wasm32-unknown-unknown`.
24//!
25//! An image at an `http` URL — a picture, a favicon, a bookmark's cover —
26//! needs an http client on the app, which `gpui_platform::application` installs
27//! and a hand-built [`gpui::Application`] does not. gpui's own default is a
28//! `NullHttpClient`, and the failure is silent: the element paints the same
29//! fallback it would show while a fetch was still in flight.
30
31#[cfg(feature = "gpui")]
32pub mod app;
33pub mod doc;
34pub mod edit;
35#[cfg(feature = "gpui")]
36pub mod fence;
37pub mod marks;
38#[cfg(feature = "gpui")]
39pub mod paint;
40pub mod parse;
41pub mod quote;
42#[cfg(feature = "gpui")]
43pub mod render;
44pub mod select;
45pub mod serialize;
46#[cfg(feature = "gpui")]
47pub mod source;
48pub mod synced;
49
50#[cfg(feature = "gpui")]
51pub use app::{
52    AppExt,
53    layout::Layout,
54    link::{Link, Links},
55    picture::PictureMenu,
56    preview::Preview,
57    typography::Typography,
58};
59pub use doc::{Align, Block, BlockKind, Doc, Form, Mark, MarkSpan, Part, QuoteKind, Quoted, Text};
60pub use edit::{Shortcut, Splice, shortcut};
61#[cfg(feature = "gpui")]
62pub use fence::{BlockRenderer, Fence, Rewrite, highlight::Highlighter};
63pub use marks::Marks;
64#[cfg(feature = "gpui")]
65pub use paint::{
66    comment::{CommentPaint, CommentWashes, default_comment},
67    find::{FindPaint, default_find, find_washes},
68    marks::{
69        HighlightColor, HighlightPaint, MarkPaint, default_highlight, highlight_solid,
70        highlight_wash,
71    },
72};
73pub use parse::{
74    ParsedDoc, is_image, is_link, is_url, parse, parse_at, parse_at_many, parse_ranges,
75    parse_ranges_with, parse_with,
76};
77pub use quote::Quote;
78#[cfg(feature = "gpui")]
79pub use render::{
80    Annotation, BlockLayouts, Caption, CopyButton, Editing, FenceHost, ImageOverlay,
81    ImageOverlayCorner, LeaveBlock, OnImage, OnImageMenu, OnJump, OnLeave, OnResize, OnRewrite,
82    OnToggle, PAINTED_CONTEXT, RevealMode, SourceText, SpanJob, Spans, Toggle, image_source,
83    markdown, render, render_source, render_with,
84};
85pub use select::{Affinity, Cursor, Selection};
86pub use serialize::{serialize, serialize_at, serialize_at_many, serialize_with};
87#[cfg(feature = "gpui")]
88pub use source::{spans as source_spans, style::SourceStyle};
89pub use synced::Synced;