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//! Nothing here depends on a UI toolkit. Glyphs carry a toolkit-agnostic
11//! [`Style`], which a frontend crate (`leaf-tui`, and next `leaf-gui`) maps onto
12//! its own styling. Both frontends share this exact caret math, edit surface,
13//! and offset⇄position mapping — the split is what lets a GUI reuse the hard
14//! parts instead of re-deriving them.
15
16pub mod doc;
17mod html;
18pub mod style;
19pub mod wysiwyg;
20
21pub use doc::{
22    Capabilities, DiskState, Doc, FootnoteDef, FootnoteRef, InlineMarks, Landing, LineFlow,
23    MarkupMode, View,
24};
25pub use style::{Baseline, Role, Style};
26pub use wysiwyg::{
27    BlockClass, Boundary, CodeBlockInfo, ColorScheme, Glyph, MediaInfo, MediaKind, MediaSource,
28    TableCell, TableInfo, TableRow, VRow, VisualMap,
29};
30
31// Re-export the twig types a frontend needs to name when calling into a `Doc`
32// (the toolbar's block/inline kinds), so frontends don't each depend on twig.
33// `Alignment` comes with `TableCell`, which carries one.
34// `Format` too: a filesystem-free host (wasm/FFI) picks the document's format
35// itself when it calls `Doc::from_source`, since there's no file extension to
36// sniff it from the way `Doc::open` does.
37// `Gesture` names one authoring capability for `Doc::supports`, the finer-grained
38// half of `Capabilities` — a frontend wanting a mark leaf's own toolbar doesn't
39// offer asks with one of these.
40pub use twig::{Alignment, BlockContainerKind, BlockKind, Format, Gesture, InlineKind};