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;
26#[cfg(feature = "syntax")]
27pub mod syntax;
28pub mod wysiwyg;
29
30pub use doc::{
31    Capabilities, DiskState, Doc, FootnoteDef, FootnoteRef, Highlight, HighlightCursor,
32    InlineMarks, Landing, LineFlow, MarkupMode, PAGE_BREAK, Quote, View, VisualKey,
33};
34pub use source::{SourceMap, StyledRun};
35pub use style::{
36    Align, Baseline, FontFamily, LineSpacing, MarkColor, Role, SizeStep, Style, Token,
37};
38pub use wysiwyg::{
39    BlockClass, Boundary, CodeBlockInfo, ColorScheme, Glyph, MediaInfo, MediaKind, MediaSource,
40    TableCell, TableInfo, TableRow, VRow, VisualMap,
41};
42
43// Re-export the twig types a frontend needs to name when calling into a `Doc`
44// (the toolbar's block/inline kinds), so frontends don't each depend on twig.
45// `Alignment` comes with `TableCell`, which carries one.
46// `Format` too: a filesystem-free host (wasm/FFI) picks the document's format
47// itself when it calls `Doc::from_source`, since there's no file extension to
48// sniff it from the way `Doc::open` does.
49// `Gesture` names one authoring capability for `Doc::supports`, the finer-grained
50// half of `Capabilities` — a frontend wanting a mark leaf's own toolbar doesn't
51// offer asks with one of these.
52pub use twig::{Alignment, BlockContainerKind, BlockKind, Format, Gesture, InlineKind};