Skip to main content

leaf_core/
lib.rs

1//! leaf-core — the frontend-neutral heart of leaf.
2//!
3//! A [`Doc`] is a `twig::Editor` plus a byte-offset caret and selection: every
4//! mutation is one of twig's offset-addressed ops, and the document stays a
5//! live, round-trippable AST the whole time you type into it. The [`wysiwyg`]
6//! module resolves that AST into a [`wysiwyg::VisualMap`] — rendered glyphs that
7//! each point back at the source byte they came from, so a caret can ride the
8//! *visible* text and step over hidden markup delimiters.
9//!
10//! The [`source`] module is that map's opposite number: where [`wysiwyg`]
11//! resolves the markup away, it styles the markup *itself*, so the source view
12//! can paint a heading's `# ` and a link's destination as the scaffolding they
13//! are. Both read the same twig AST, so the two views cannot disagree about what
14//! the document is.
15//!
16//! Nothing here depends on a UI toolkit. Glyphs carry a toolkit-agnostic
17//! [`Style`], which a frontend crate (`leaf-tui`, and next `leaf-gui`) maps onto
18//! its own styling. Both frontends share this exact caret math, edit surface,
19//! and offset⇄position mapping — the split is what lets a GUI reuse the hard
20//! parts instead of re-deriving them.
21
22pub mod doc;
23mod html;
24pub mod source;
25pub mod style;
26pub mod wysiwyg;
27
28pub use doc::{
29    Capabilities, DiskState, Doc, FootnoteDef, FootnoteRef, Highlight, HighlightCursor,
30    InlineMarks, Landing, LineFlow, MarkupMode, Quote, View,
31};
32pub use source::{SourceMap, StyledRun};
33pub use style::{Baseline, Role, Style};
34pub use wysiwyg::{
35    BlockClass, Boundary, CodeBlockInfo, ColorScheme, Glyph, MediaInfo, MediaKind, MediaSource,
36    TableCell, TableInfo, TableRow, VRow, VisualMap,
37};
38
39// Re-export the twig types a frontend needs to name when calling into a `Doc`
40// (the toolbar's block/inline kinds), so frontends don't each depend on twig.
41// `Alignment` comes with `TableCell`, which carries one.
42// `Format` too: a filesystem-free host (wasm/FFI) picks the document's format
43// itself when it calls `Doc::from_source`, since there's no file extension to
44// sniff it from the way `Doc::open` does.
45// `Gesture` names one authoring capability for `Doc::supports`, the finer-grained
46// half of `Capabilities` — a frontend wanting a mark leaf's own toolbar doesn't
47// offer asks with one of these.
48pub use twig::{Alignment, BlockContainerKind, BlockKind, Format, Gesture, InlineKind};