Skip to main content

Crate leaf_core

Crate leaf_core 

Source
Expand description

leaf-core — the frontend-neutral heart of leaf.

A Doc is a twig::Editor plus a byte-offset caret and selection: every mutation is one of twig’s offset-addressed ops, and the document stays a live, round-trippable AST the whole time you type into it. The wysiwyg module resolves that AST into a wysiwyg::VisualMap — rendered glyphs that each point back at the source byte they came from, so a caret can ride the visible text and step over hidden markup delimiters.

The source module is that map’s opposite number: where wysiwyg resolves the markup away, it styles the markup itself, so the source view can paint a heading’s # and a link’s destination as the scaffolding they are. Both read the same twig AST, so the two views cannot disagree about what the document is.

The counts module reads that same rendering back as numbers — words, characters, paragraphs — so a host’s word count is a count of what the page shows rather than of the markup underneath it.

The frame module is for the bindings that hand that rendering across a boundary: it says which rows one frame changed from the frame before, so a binding can cross only those.

Nothing here depends on a UI toolkit. Glyphs carry a toolkit-agnostic Style, which a frontend crate (leaf-tui, and next leaf-gui) maps onto its own styling. Both frontends share this exact caret math, edit surface, and offset⇄position mapping — the split is what lets a GUI reuse the hard parts instead of re-deriving them.

Re-exports§

pub use counts::TextCounts;
pub use doc::Capabilities;
pub use doc::DiskState;
pub use doc::Doc;
pub use doc::DropTarget;
pub use doc::FootnoteDef;
pub use doc::FootnoteRef;
pub use doc::Heading;
pub use doc::Highlight;
pub use doc::HighlightCursor;
pub use doc::InlineMarks;
pub use doc::Landing;
pub use doc::LineFlow;
pub use doc::MarkupMode;
pub use doc::PAGE_BREAK;
pub use doc::Quote;
pub use doc::View;
pub use doc::VisualKey;
pub use frame::RowDelta;
pub use frame::apply_row_delta;
pub use frame::row_delta;
pub use source::SourceMap;
pub use source::StyledRun;
pub use style::Align;
pub use style::Baseline;
pub use style::FaceId;
pub use style::FaceRef;
pub use style::FaceTable;
pub use style::FontFace;
pub use style::FontFamily;
pub use style::FontSize;
pub use style::Hundredths;
pub use style::LineHeight;
pub use style::LineSpacing;
pub use style::MarkColor;
pub use style::Role;
pub use style::SizeStep;
pub use style::Style;
pub use style::TextColor;
pub use style::Token;
pub use wysiwyg::BlockClass;
pub use wysiwyg::Boundary;
pub use wysiwyg::CodeBlockInfo;
pub use wysiwyg::ColorScheme;
pub use wysiwyg::Glyph;
pub use wysiwyg::MathInfo;
pub use wysiwyg::MathMark;
pub use wysiwyg::MediaInfo;
pub use wysiwyg::MediaKind;
pub use wysiwyg::MediaSource;
pub use wysiwyg::Reveal;
pub use wysiwyg::Surface;
pub use wysiwyg::TableCell;
pub use wysiwyg::TableInfo;
pub use wysiwyg::TableRow;
pub use wysiwyg::VRow;
pub use wysiwyg::VisualMap;

Modules§

counts
Word, character, and paragraph counts over the text a reader sees.
doc
The document model: a twig::Editor plus a byte-offset caret and selection.
frame
What one frame’s rows are as a change from the frame before’s.
source
Syntax highlighting for the source view — the AST read as markup rather than as rendered text.
style
A toolkit-neutral text style — the seam that lets one document model drive any frontend.
syntax
Syntax highlighting for a fenced code block: the lines of a block and the language its fence names in, a Token per byte range out.
wysiwyg
The WYSIWYG view: render the document with its markup resolved, not shown — headings and code tagged with a typographic role (a frontend sizes or colours them; see crate::style), **bold** as real bold, # / ** / ` delimiters hidden — while keeping every visible glyph tied back to the source byte it came from.

Enums§

Alignment
Table-cell alignment: written via Builder::add_cell, read back on FlatNode::alignment.
BlockContainerKind
A block container for Editor::toggle_block_container — the toolbar’s Quote / Bulleted list / Numbered list buttons. Where a BlockKind rewrites one block’s leading marker, a container prefixes every line of a range and nests. Djot and Markdown spell all three; other formats yield Error::UnsupportedFormat.
BlockKind
A block target for Editor::set_block — the toolbar’s H1…H6 / Body switch.
Format
Every format Twig can parse — the input axis, as opposed to Target, which is where output bytes can go.
Gesture
One authoring gesture, named with whatever kind it takes — the question Format::supports answers.
InlineKind
An inline mark for Editor::wrap_range / Editor::toggle_inline — a rich editor’s Bold / Italic / Code / … buttons. Djot spells all of them; Markdown spells InlineKind::Strong, InlineKind::Emph, InlineKind::Verbatim and InlineKind::Delete — GFM strikethrough is parsed by default, so every editor this crate creates authors it — plus InlineKind::Mark once MarkdownExtensions::highlight is set, since ==x== is otherwise text the reparse hands back unchanged. An unsupported kind yields Error::UnsupportedFormat; Format::supports_with is the question asked ahead of the call.