pub struct Document {
pub meta: NodeMeta,
pub children: Vec<Block>,
/* private fields */
}Expand description
The root of a document: a sequence of top-level Blocks, and for a
parsed document the source it was parsed from.
The source is the only truth: writing a parsed document back with
Document::to_markdown reuses the source of every top-level block that
did not change. Only parse() gives a document a
source; Document::without_source drops it, and a document without one
is written as canonical Markdown.
Fields§
§meta: NodeMetaNode metadata (source span).
children: Vec<Block>The document’s top-level blocks, in source order.
Implementations§
Source§impl Document
impl Document
Sourcepub fn reread_kept_sources(&mut self)
pub fn reread_kept_sources(&mut self)
Builds again, with this document’s definitions, every leaf that keeps
the text it was built from (with_source), as with_source builds it,
keeping the leaf’s span and its other fields. A leaf built with other
definitions than the document’s, or kept after the document’s
definitions changed, holds inlines its text no longer reads as, and
the writer then writes it from its inlines; this makes it read as its
text again.
Source§impl Document
impl Document
Sourcepub fn source(&self) -> Option<&str>
pub fn source(&self) -> Option<&str>
The input this document was parsed from, or None for a document
built by hand or returned by Document::without_source.
Sourcepub fn without_source(self) -> Self
pub fn without_source(self) -> Self
This document without its source; writing it gives canonical Markdown.
Source§impl Document
impl Document
Sourcepub fn inline_source(&self, path: &NodePath) -> Option<InlineSource>
pub fn inline_source(&self, path: &NodePath) -> Option<InlineSource>
The inline content the parser read for the leaf at path: a
paragraph, a heading, a table cell (its table’s path, its row’s index,
and its own), or the label of a leaf or container directive (its
directive’s path), read again from the source of the top-level block
holding it, so that the cost is linear in that block. None for a
document without a source, or a path that names no such leaf, a
directive without a label, or a node without a span or one the source
does not hold.
Sourcepub fn leaf_sources(&self) -> Vec<(NodePath, InlineSource)>
pub fn leaf_sources(&self) -> Vec<(NodePath, InlineSource)>
The path and inline source of every leaf of the document, in document
order, each as Document::inline_source returns it, read in one
pass over the source. Empty for a document without a source.
Source§impl Document
impl Document
Sourcepub fn to_markdown(&self) -> Result<String, SerializeError>
pub fn to_markdown(&self) -> Result<String, SerializeError>
Write this document as Markdown with default options: the source of every unchanged node, the source of its own syntax around a node whose children changed, and canonical Markdown for the rest.
Sourcepub fn to_markdown_with(
&self,
options: &SerializeOptions,
) -> Result<String, SerializeError>
pub fn to_markdown_with( &self, options: &SerializeOptions, ) -> Result<String, SerializeError>
Write this document as Markdown with explicit options. A document with a source reuses it for each node that corresponds to the node the source parses to at the same span, and for the own syntax of one whose children changed; the options apply to the rest.