Skip to main content

Document

Struct Document 

Source
pub struct Document { /* private fields */ }

Implementations§

Source§

impl Document

Source

pub fn parse(input: &[u8], format: Format) -> Result<Self, Error>

Source

pub fn parse_str(input: &str, format: Format) -> Result<Self, Error>

Source

pub fn render_html(&mut self) -> Result<Vec<u8>, Error>

Render the document to HTML. For Djot/Markdown this is the rich rendering path that resolves reference/footnote side tables.

Source

pub fn serialize(&mut self, format: Format) -> Result<Vec<u8>, Error>

Serialize the document to format’s own source syntax: a round-trip when format matches the document’s own format, cross-format conversion otherwise (e.g. parse Markdown, serialize as Djot). Returns Error::UnsupportedFormat when the requested direction has no serializer (today: converting into XML from another format).

Source

pub fn ast_json(&mut self) -> Result<Vec<u8>, Error>

Encode the document’s AST as pretty-printed JSON (the same encoding as twig convert -o ast).

Source

pub fn query(&mut self, selector: &str) -> Result<Vec<QueryMatch>, Error>

Resolve a CSS-lite selector (e.g. heading[level=2], link[dest^="http"], code, list > item) against the document, returning one QueryMatch per matching node in document order. A malformed selector yields Error::InvalidArgument.

This is the general replacement for scanning code spans by hand: a verbatim / code_block / raw_inline / raw_block selector recovers those, and every other node kind is reachable too.

Trait Implementations§

Source§

impl Debug for Document

Source§

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

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

impl Drop for Document

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.