#[non_exhaustive]pub struct FlatNode {Show 18 fields
pub id: NodeId,
pub parent: Option<NodeId>,
pub first_child: Option<NodeId>,
pub next_sibling: Option<NodeId>,
pub span: Range<usize>,
pub content_span: Option<Range<usize>>,
pub level: Option<u32>,
pub kind: Kind,
pub text: Option<String>,
pub destination: Option<String>,
pub head: Option<bool>,
pub alignment: Option<Alignment>,
pub name: Option<String>,
pub directive_form: Option<DirectiveForm>,
pub origin: Option<ContainerOrigin>,
pub marker_span: Option<Range<usize>>,
pub checked: Option<bool>,
pub attrs: Vec<(String, Option<String>)>,
}Expand description
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.
#[non_exhaustive]: a snapshot node is something twig hands you, never
something you build, so it gains a field whenever a node kind’s payload is
surfaced (as head/alignment were for tables). Sealing construction here
keeps every future addition a minor release instead of a major one.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: NodeId§parent: Option<NodeId>§first_child: Option<NodeId>§next_sibling: Option<NodeId>§span: Range<usize>§content_span: Option<Range<usize>>§level: Option<u32>A heading’s level; None for every other kind.
kind: Kind§text: Option<String>§destination: Option<String>§head: Option<bool>Whether a row/cell belongs to the table head; None for every other
kind.
alignment: Option<Alignment>A cell’s column alignment; None for every other kind. The delimiter
row (|:--|--:|) that spells the alignment out is consumed by the parser
and has no node of its own, so this is the only way to recover it.
Alignment::Default is a real, unspecified alignment (a bare ---) —
distinct from the None a non-cell node reports.
name: Option<String>The name a generic container carries in its own payload rather than in
kind: an HTML/XML tag ("picture", "source", …) or a directive type
("note", "embed", "vis", …, no leading colons). None for every
semantic kind, whose identity is kind alone. With this an
html_elements parse’s <picture>/<source> are distinguishable — both
report kind == "container" — and so are a ::embed and a ::toc.
A tag and a directive type share one kind because they are one concept
in the core: a named container with attributes and children. name is
what tells them apart, which is why it is not optional in practice for
anything a renderer cares about.
directive_form: Option<DirectiveForm>Which of the three generic-container SPELLINGS this node’s producer
draws; None when it draws none. Pairs with name: the
name says which container, this says how it is written, and a
renderer needs both — the same type is a span inline
(DirectiveForm::Text), a standalone block with no body
(DirectiveForm::Leaf), and a wrapper around blocks
(DirectiveForm::Container).
This does not answer “is it a directive?” — use
origin. HTML’s parser sets a form on <div> and
<span>, the two tags djot and Markdown have generic spellings for, so
this reports Some(Container) for a <div> and None for a
<video>: right often enough to look usable, wrong on the two tags you
meet first.
origin: Option<ContainerOrigin>Whether a generic container was WRITTEN as a tag or as a directive;
None when nothing recorded it — the node is not a container, or no
parser produced it (a Builder tree).
This is the field that separates an HTML <div> from a Markdown
:::div. Those two agree on kind ("container"), on
name ("div") and on
directive_form (Container), field for field,
so none of the three can tell you which one you have.
marker_span: Option<Range<usize>>The node’s own MARKER — the leading bytes a rich view HIDES, on its
opening line: a heading’s #s and the space after them, a list item’s
- / 1. , a task item’s marker plus its [x] box, a block quote’s
> . None for a node with no leading marker (every inline, a
paragraph, a SETEXT heading whose --- sits under the block).
Not derivable from span and
content_span. For a heading it happens to be
span.start..content_span.start; for a marker-prefixed container it is
not, because those report content_span == span — a prefix repeating on
every line has no contiguous interior to point at. Before this field the
answer was recoverable only by a per-format rule (from the item’s inner
paragraph in Markdown, from the item itself in Djot), which is the
“which parser produced this?” reasoning a shared AST exists to remove.
Covers ONE LINE, and this node’s own marker alone. For the whole prefix a
nested construct sits behind (> 1. [ ] is four nodes’ markers plus
the indent between them), call Document::line_prefix.
checked: Option<bool>A task list item’s checkbox state; None for every other kind.
The parser has always known this — it is what decides
Kind::TaskListItem over Kind::ListItem in the first place — and
until now nothing surfaced it, so a consumer rendering a clickable
checkbox re-derived the state by scanning the source for [x]. That scan
is fooled by a [ in prose, and it asks the bytes a question the tree
had already answered. Twig would WRITE a checkbox
(Editor::set_task_checked) and not read one back.
None is distinct from Some(false): a consumer treating “not a task
item” as unchecked draws an empty box beside every paragraph.
attrs: Vec<(String, Option<String>)>The node’s {...} / HTML attributes as (key, value) pairs in source
order (empty when it has none). A bare attribute (HTML disabled, or a
<source media=…> used as a flag) has a None value.