Skip to main content

Crate twig

Crate twig 

Source

Structs§

Builder
Programmatic construction of a document — the write-path mirror of Document::parse. Build the tree bottom-up (add children, then the container, wiring them with Builder::set_children); every add* method returns the new node’s NodeId. Then render, serialize, query, or dump the subtree rooted at any id, on demand, without consuming the builder. All input strings are copied, so caller buffers need not outlive a call.
Change
The byte-level effect of an Editor edit: old is the range of the pre-edit source that was replaced, new the range the replacement now occupies in the post-edit source (they share a start). An insertion has an empty old; a deletion an empty new. Everything a caret/selection needs to re-anchor across an edit without re-diffing: shift any offset >= old.end by new.len() - old.len().
Document
Editor
A span-splice editor over a document: applies lossless, in-place edits and reparses after each one, so node addressing stays valid as the document evolves. Every op is addressed by a locator — a dot-separated index path ("0.3.1") or a selector that must match exactly one node (heading("Status")). A failed edit leaves the document unchanged.
FlatNode
One node of an Editor::nodes snapshot — the flat AST arena as owned Rust data (the JSON-free read path). id indexes the snapshot; parent, first_child, and next_sibling link the tree (None where absent). text is the node’s primary payload (a str’s bytes, a code_block’s body, …) and destination a link/image target, each None when the kind carries no such payload.
MarkdownExtensions
Markdown extensions to enable for an Editor parse (see Editor::new_ext). Ignored for non-Markdown formats. Both default off, matching the library.
NodeId
The id of a node added to a Builder, returned by every add* method and used to wire up the tree via Builder::set_children and to root a render/serialize/query.
QueryMatch
One node returned by Document::query: its AST id, byte spans, and kind.
Span
C ABI mirror of Zig’s TwigSpan — a byte range [start, end).
Version

Enums§

Alignment
Table-cell alignment for Builder::add_cell.
BlockKind
A block target for Editor::set_block — the toolbar’s H1…H6 / Body switch.
BulletStyle
Bullet marker style for Builder::add_bullet_list.
DirectiveForm
The surface form of a generic directive for Builder::add_directive.
Error
Format
InlineKind
An inline mark for Editor::wrap_range / Editor::toggle_inline — a rich editor’s Bold / Italic / Code / … buttons. Markdown spells only InlineKind::Strong, InlineKind::Emph, and InlineKind::Verbatim; Djot spells all of them. An unsupported kind yields Error::UnsupportedFormat.
OrderedDelim
Delimiter around an ordered-list number (1., 1), (1)).
OrderedNumbering
Numbering scheme for Builder::add_ordered_list.
SmartPunctuation
The smart-punctuation kind for Builder::add_smart_punctuation.
TextKind
The single-string-payload node kinds, addable via Builder::add_text.
VoidKind
The void-payload node kinds, addable via Builder::add. Kinds with a payload have their own dedicated add_* method instead.

Constants§

ABI_VERSION
The C ABI contract version this crate was compiled against — the compile-time counterpart to abi_version (which reports the linked library’s). This crate builds and links its own vendored copy of the Zig source, so the two always agree; the pair is exposed so a consumer embedding a separately-built library can verify layout compatibility at load time.

Functions§

abi_version
The C ABI contract version of the linked library. This crate is written against ABI_VERSION; the two agreeing is what makes the #[repr(C)] mirrors in ffi sound. It is bumped only on a breaking ABI change (a struct layout change or a renumbered enum value), never on an additive one (a new format code or a new function).
version
version_string