Skip to main content

Document

Struct Document 

Source
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: NodeMeta

Node metadata (source span).

§children: Vec<Block>

The document’s top-level blocks, in source order.

Implementations§

Source§

impl Document

Source

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

Source

pub fn new(children: Vec<Block>) -> Self

A document holding children and no source.

Source

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.

Source

pub fn without_source(self) -> Self

This document without its source; writing it gives canonical Markdown.

Source§

impl Document

Source

pub fn to_html(&self) -> Result<String, HtmlError>

Render this document to safe-by-default HTML with default options.

Source

pub fn to_html_with(&self, options: &HtmlOptions) -> Result<String, HtmlError>

Render this document to HTML with explicit options.

Source§

impl Document

Source

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.

Source

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

Source

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.

Source

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.

Source§

impl Document

Source

pub fn validate(&self) -> Vec<Diagnostic>

Validate this document’s AST shape, returning a diagnostic for each invalid or unsupported node (empty when the document is well-formed).

Trait Implementations§

Source§

impl Clone for Document

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Document

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Document

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Document

Source§

impl From<Vec<Block>> for Document

Source§

fn from(children: Vec<Block>) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Document

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Document

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.