lsdocs_doctree #
Document tree (AST) types: nodes, spans and metadata.
A Document is what a parser produces and what transformers and
renderers consume. Every type here crosses process boundaries, so the
serialized shape is part of the public API:
- Nodes are tagged by a
typefield, e.g.{"type": "heading", "level": 1, "children": [...]}. - Field names are
snake_case. - Optional fields are omitted when empty, and unknown fields are ignored when reading, so new fields can be added without breaking older plugins.
Formats without a core node kind use Node::Custom.
The shape every parser produces
Parsers for any source format hand transformers the same shape:
- Sections nest. Content under a title is wrapped in a
Node::Sectionwhose first child is the titleHeading, with subsections nested inside it. A section's anchor id isSection::id;Heading::idis only for headings outside the section tree (e.g. inside a block quote). Content before the first title stays at the top level. - Ids are explicit or left out. Parsers set ids the author wrote
(e.g.
{#id}in Markdown, labels in reStructuredText). The host gives every other section a unique id derived from its title after parsing. - Cross-document links carry a
LinkTarget. The host fills it in for relative links to other documents; parsers set it for references that are not paths, such as labels.
type alias Value #
pub type Value = Value;An arbitrary structured value, as found in front matter or plugin data.
type alias Metadata #
pub type Metadata = ;Document-level metadata, such as front matter.
struct Span #
A byte range within the document's source text.
Offsets count UTF-8 bytes from the start of the source, and end is
exclusive. The source file is the enclosing Document::source.
Trait implementations
DebugCloneCopyStructuralPartialEqPartialEqEqHashSerializeDeserialize<'de>(impl<'de>)
field start #
pub start: u32Offset of the first byte.
field end #
pub end: u32Offset one past the last byte.
function new #
pub const Creates a span from start (inclusive) to end (exclusive).
struct Document #
A parsed source document.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)
field source #
pub source: StringPath of the source file, relative to the site's source directory,
with / separators.
field metadata #
pub metadata: MetadataFront matter and other document-level data.
field children #
pub children: Top-level nodes.
function new #
Creates an empty document for the given source path.
method descendants #
Iterates over every node in the document, depth first, parents before children.
method title #
The document's title: its title metadata if that is a string, else
the text of its first heading.
function plain_text #
The text of nodes without markup: text, inline code and image alt
text, in order.
struct Descendants #
Depth-first iterator returned by Document::descendants and
Node::descendants.
Trait implementations
enum Node #
A node in the document tree.
Serialized with a type tag holding the Node::kind name, for core
kinds, followed by the variant's fields.
Trait implementations
DebugCloneStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<Section>From<Heading>From<Paragraph>From<List>From<ListItem>From<BlockQuote>From<CodeBlock>From<Table>From<TableRow>From<TableCell>From<ThematicBreak>From<Raw>From<Text>From<Emphasis>From<Strong>From<InlineCode>From<Link>From<Image>From<LineBreak>From<Admonition>From<DefinitionList>From<DefinitionTerm>From<DefinitionDescription>From<FootnoteReference>From<FootnoteDefinition>From<Math>From<Figure>From<Caption>From<Anchor>From<PendingReference>From<ObjectTarget>From<Custom>
variant Section #
SectionA titled section; by convention its first child is a Heading.
variant Heading #
HeadingA heading.
variant Paragraph #
ParagraphA paragraph.
variant List #
ListA bulleted or numbered list whose children are list items.
variant ListItem #
ListItemAn item of a List.
variant BlockQuote #
BlockQuoteA block quote.
variant CodeBlock #
CodeBlockA block of code or preformatted text.
variant Table #
TableA table whose children are table rows.
variant TableRow #
TableRowA row of a Table whose children are table cells.
variant TableCell #
TableCellA cell of a TableRow.
variant ThematicBreak #
ThematicBreakA horizontal rule.
variant Raw #
RawContent passed through verbatim to renderers of a matching format, such as inline HTML in Markdown.
variant Text #
TextPlain text.
variant Emphasis #
EmphasisEmphasized (usually italic) text.
variant Strong #
StrongStrongly emphasized (usually bold) text.
variant InlineCode #
InlineCodeInline code.
variant Link #
LinkA hyperlink.
variant Image #
ImageAn image.
variant LineBreak #
LineBreakA hard line break.
variant Admonition #
AdmonitionA callout such as a note or warning.
variant DefinitionList #
DefinitionListA list of terms and their descriptions: children alternate between
Node::DefinitionTerm and one or more
Node::DefinitionDescriptions.
variant DefinitionTerm #
DefinitionTermA term in a DefinitionList.
variant DefinitionDescription #
DefinitionDescriptionThe description of the term before it in a DefinitionList.
variant FootnoteReference #
FootnoteReferenceA reference to a footnote, e.g. [^1].
variant FootnoteDefinition #
FootnoteDefinitionThe text of a footnote.
variant Math #
MathA mathematical formula, inline or on its own line.
variant Figure #
FigureContent (usually an image) with an optional Node::Caption as its
last child.
variant Caption #
CaptionThe caption of a Figure.
variant Anchor #
AnchorA link target with no content of its own, e.g. a reStructuredText label in front of a paragraph.
variant PendingReference #
PendingReferenceA cross-reference no plugin has resolved yet, e.g. :py:func: to an
object documented elsewhere. Resolvers replace it with a link, or
leave it for a later one; the host reports and unwraps what is left.
variant ObjectTarget #
ObjectTargetAn anchor naming a documented object (domain, kind, name), so that
inventories of the site can list it. Otherwise like
Node::Anchor.
variant Custom #
CustomA node kind defined by a plugin rather than by lsdocs.
method kind #
The name plugins use to select this node, e.g. in transformer
capabilities: the type tag for core kinds ("heading"), or
"custom:<kind>" for custom nodes.
method span #
Where this node came from in the source, if known.
method span_mut #
Mutable access to where this node came from, e.g. to move spans found in a piece of text to where that piece is in the source.
method children #
This node's children; empty for leaf kinds.
method children_mut #
Mutable access to this node's children, or None for leaf kinds.
method anchor_id #
The anchor id this node defines without content of its own: an
Node::Anchor's or an Node::ObjectTarget's.
method descendants #
Iterates over this node and everything below it, depth first.
struct Section #
See Node::Section.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<Section>
field span #
pub span: Where this node came from in the source, if known.
field id #
pub id: Anchor identifier for linking to the section. Set by the parser if the author gave one; otherwise the host derives one from the title.
field children #
pub children: Content of the section.
struct Heading #
See Node::Heading.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<Heading>
field span #
pub span: Where this node came from in the source, if known.
field level #
pub level: u8Heading level, from 1 (top) to 6. For a section title this is the level as written, which may skip levels; the nesting of sections is the structure.
field id #
pub id: Anchor identifier, only for headings that are not a section's
title (a section's anchor is Section::id).
field children #
pub children: Inline content.
struct Paragraph #
See Node::Paragraph.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<Paragraph>
field span #
pub span: Where this node came from in the source, if known.
field children #
pub children: Inline content.
struct List #
See Node::List.
Trait implementations
field span #
pub span: Where this node came from in the source, if known.
field ordered #
pub ordered: boolWhether items are numbered.
field start #
pub start: Number of the first item of an ordered list, if not 1.
field children #
pub children: The list's items.
struct ListItem #
See Node::ListItem.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<ListItem>
field span #
pub span: Where this node came from in the source, if known.
field checked #
pub checked: For task list items, whether the box is checked.
field children #
pub children: Content of the item.
struct BlockQuote #
See Node::BlockQuote.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<BlockQuote>
field span #
pub span: Where this node came from in the source, if known.
field children #
pub children: Quoted content.
struct CodeBlock #
See Node::CodeBlock.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<CodeBlock>
field span #
pub span: Where this node came from in the source, if known.
field language #
pub language: Language name, e.g. "rust", if given.
field info #
pub info: Anything after the language on a Markdown fence's info line.
field value #
pub value: StringThe code itself.
struct Table #
See Node::Table.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<Table>
field span #
pub span: Where this node came from in the source, if known.
field align #
pub align: Alignment of each column.
field children #
pub children: The table's rows.
struct TableRow #
See Node::TableRow.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<TableRow>
field span #
pub span: Where this node came from in the source, if known.
field header #
pub header: boolWhether this is a header row.
field children #
pub children: The row's cells.
struct TableCell #
See Node::TableCell.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<TableCell>
field span #
pub span: Where this node came from in the source, if known.
field children #
pub children: Content of the cell.
struct ThematicBreak #
See Node::ThematicBreak.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<ThematicBreak>
field span #
pub span: Where this node came from in the source, if known.
struct Raw #
See Node::Raw.
Trait implementations
field span #
pub span: Where this node came from in the source, if known.
field format #
pub format: StringOutput format the content is meant for, e.g. "html".
field value #
pub value: StringThe verbatim content.
struct Text #
See Node::Text.
Trait implementations
field span #
pub span: Where this node came from in the source, if known.
field value #
pub value: StringThe text.
struct Emphasis #
See Node::Emphasis.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<Emphasis>
field span #
pub span: Where this node came from in the source, if known.
field children #
pub children: Emphasized content.
struct Strong #
See Node::Strong.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<Strong>
field span #
pub span: Where this node came from in the source, if known.
field children #
pub children: Strongly emphasized content.
struct InlineCode #
See Node::InlineCode.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<InlineCode>
field span #
pub span: Where this node came from in the source, if known.
field value #
pub value: StringThe code.
struct Link #
See Node::Link.
Trait implementations
field span #
pub span: Where this node came from in the source, if known.
field url #
pub url: StringLink target.
field title #
pub title: Link title (often shown as a tooltip).
field target #
pub target: Where the link points inside the site, if it is a
cross-reference. Renderers prefer it over url.
field children #
pub children: Link text.
struct LinkTarget #
The site-internal destination of a Link.
A resolved target names a document, an anchor, or both (an anchor alone
means the linking document). An unresolved one has only a label, to be
looked up among the anchors of every document, e.g. by a transformer.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqEqSerializeDeserialize<'de>(impl<'de>)
field document #
pub document: Source path of the target document, relative to the source
directory with / separators.
field anchor #
pub anchor: Anchor id within the target document.
field label #
pub label: A label naming the target, not yet resolved to a document and anchor.
struct Image #
See Node::Image.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<Image>
field span #
pub span: Where this node came from in the source, if known.
field url #
pub url: StringImage location.
field alt #
pub alt: StringAlternative text.
field title #
pub title: Image title (often shown as a tooltip).
struct LineBreak #
See Node::LineBreak.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<LineBreak>
field span #
pub span: Where this node came from in the source, if known.
struct Admonition #
See Node::Admonition.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<Admonition>
field span #
pub span: Where this node came from in the source, if known.
field kind #
pub kind: StringWhat kind of callout, e.g. "note", "tip", "warning".
field title #
pub title: A title replacing the kind's default one.
field children #
pub children: Content.
struct DefinitionList #
See Node::DefinitionList.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<DefinitionList>
field span #
pub span: Where this node came from in the source, if known.
field children #
pub children: Terms and descriptions, in order.
struct DefinitionTerm #
See Node::DefinitionTerm.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<DefinitionTerm>
field span #
pub span: Where this node came from in the source, if known.
field children #
pub children: Inline content.
struct DefinitionDescription #
See Node::DefinitionDescription.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<DefinitionDescription>
field span #
pub span: Where this node came from in the source, if known.
field children #
pub children: Content.
struct FootnoteReference #
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<FootnoteReference>
field span #
pub span: Where this node came from in the source, if known.
field label #
pub label: StringThe footnote's label, e.g. "1" or "note".
struct FootnoteDefinition #
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<FootnoteDefinition>
field span #
pub span: Where this node came from in the source, if known.
field label #
pub label: StringThe label references use.
field children #
pub children: Content.
struct Math #
See Node::Math.
Trait implementations
field span #
pub span: Where this node came from in the source, if known.
field value #
pub value: StringThe formula, e.g. in TeX notation.
field display #
pub display: boolWhether it is set on its own line rather than inline.
struct Figure #
See Node::Figure.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<Figure>
field span #
pub span: Where this node came from in the source, if known.
field id #
pub id: Anchor identifier, e.g. for linking to the figure.
field children #
pub children: Content, then an optional caption.
struct Caption #
See Node::Caption.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<Caption>
field span #
pub span: Where this node came from in the source, if known.
field children #
pub children: Content.
struct Anchor #
See Node::Anchor.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<Anchor>
field span #
pub span: Where this node came from in the source, if known.
field id #
pub id: StringThe anchor identifier.
struct PendingReference #
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<PendingReference>
field span #
pub span: Where this node came from in the source, if known.
field domain #
pub domain: StringThe domain: py, cpp, js, ..., or std for labels, terms
and documents.
field role #
pub role: StringThe role without its domain: func, class, ref, doc, ...
field target #
pub target: StringThe target as written, title split off, ~ and a leading .
removed.
field scope #
pub scope: The qualified scope it was written in (module, class), innermost last, for scoped lookups.
field explicit #
pub explicit: boolWhether the author gave a title. If not, a resolver may replace
children with a better one.
field attrs #
pub attrs: Domain-specific extras.
field children #
pub children: What to show, resolved or not.
struct ObjectTarget #
See Node::ObjectTarget.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<ObjectTarget>
field span #
pub span: Where this node came from in the source, if known.
field id #
pub id: StringThe anchor identifier, as Anchor::id.
field domain #
pub domain: StringThe domain: py, cpp, std, ...
field kind #
pub kind: StringThe object type as inventories name it: function, class,
label, term, ...
field name #
pub name: StringThe fully qualified name, e.g. os.path.join.
field display #
pub display: A display name, if it differs from name (a section's title,
say).
struct Custom #
See Node::Custom.
Trait implementations
DebugCloneDefaultStructuralPartialEqPartialEqSerializeDeserialize<'de>(impl<'de>)From<Custom>
field span #
pub span: Where this node came from in the source, if known.
field kind #
pub kind: StringThe plugin-defined kind, e.g. "mermaid". Selected as
"custom:<kind>".
field attrs #
pub attrs: Arbitrary attributes.
field children #
pub children: Child nodes, if any.
enum Align #
Horizontal alignment of a table column.
Trait implementations
DebugCloneCopyDefaultStructuralPartialEqPartialEqEqHashSerializeDeserialize<'de>(impl<'de>)
variant None #
NoneNo alignment specified.
variant Left #
LeftLeft-aligned.
variant Center #
CenterCentered.
variant Right #
RightRight-aligned.
function text #
Shorthand for a Text node.