Skip to main content

Node

Enum Node 

Source
pub enum Node {
Show 35 variants Root(Root), Fragment(Fragment), Blockquote(Blockquote), FootnoteDefinition(FootnoteDefinition), MdxJsxFlowElement(MdxJsxFlowElement), List(List), MdxjsEsm(MdxjsEsm), Toml(Toml), Yaml(Yaml), Break(Break), InlineCode(InlineCode), InlineMath(InlineMath), Delete(Delete), Emphasis(Emphasis), MdxTextExpression(MdxTextExpression), FootnoteReference(FootnoteReference), Html(Html), Image(Image), ImageReference(ImageReference), MdxJsxTextElement(MdxJsxTextElement), Link(Link), LinkReference(LinkReference), Strong(Strong), Text(Text), Code(Code), Math(Math), MdxFlowExpression(MdxFlowExpression), Heading(Heading), Table(Table), ThematicBreak(ThematicBreak), TableRow(TableRow), TableCell(TableCell), ListItem(ListItem), Definition(Definition), Paragraph(Paragraph),
}
Expand description

Nodes.

Variants§

§

Root(Root)

Root.

§

Fragment(Fragment)

A transparent fragment containing a sequence of nodes.

Fragments are useful for holding children extracted from another node.

§

Blockquote(Blockquote)

Block quote.

§

FootnoteDefinition(FootnoteDefinition)

Footnote definition.

§

MdxJsxFlowElement(MdxJsxFlowElement)

MDX: JSX element (container).

§

List(List)

List.

§

MdxjsEsm(MdxjsEsm)

MDX.js ESM.

§

Toml(Toml)

Toml.

§

Yaml(Yaml)

Yaml.

§

Break(Break)

Break.

§

InlineCode(InlineCode)

Code (phrasing).

§

InlineMath(InlineMath)

Math (phrasing).

§

Delete(Delete)

Delete.

§

Emphasis(Emphasis)

Emphasis.

§

MdxTextExpression(MdxTextExpression)

§

FootnoteReference(FootnoteReference)

Footnote reference.

§

Html(Html)

Html (phrasing).

§

Image(Image)

Image.

§

ImageReference(ImageReference)

Image reference.

§

MdxJsxTextElement(MdxJsxTextElement)

Link.

§

LinkReference(LinkReference)

Link reference.

§

Strong(Strong)

Strong

§

Text(Text)

Text.

§

Code(Code)

Code (flow).

§

Math(Math)

Math (flow).

§

MdxFlowExpression(MdxFlowExpression)

§

Heading(Heading)

Heading.

§

Table(Table)

Html (flow). Table.

§

ThematicBreak(ThematicBreak)

Thematic break.

§

TableRow(TableRow)

Table row.

§

TableCell(TableCell)

Table cell.

§

ListItem(ListItem)

List item.

§

Definition(Definition)

Definition.

§

Paragraph(Paragraph)

Paragraph.

Implementations§

Source§

impl Node

Source

pub fn children(&self) -> Option<&Vec<Node>>

Source

pub fn children_mut(&mut self) -> Option<&mut Vec<Node>>

Source

pub fn position(&self) -> Option<&Position>

Source

pub fn position_mut(&mut self) -> Option<&mut Position>

Source

pub fn position_set(&mut self, position: Option<Position>)

Source

pub fn walk<'a>(&'a self, visitor: impl FnMut(&'a Node))

Visit this node and its descendants in depth-first, pre-order.

Source

pub fn walk_mut(&mut self, visitor: impl FnMut(&mut Node))

Mutably visit this node and its descendants in depth-first, pre-order.

Source

pub fn text_content(&self) -> String

Return the concatenated text represented by this node.

Image nodes contribute their alt text and hard breaks contribute a newline. Structural nodes concatenate the text of their children.

Source

pub fn find_heading(&self, title: &str) -> Option<&Node>

Find a direct child heading with the requested text.

Source

pub fn code_language(&self) -> Option<&str>

Return the language identifier of inline or fenced code.

Source

pub fn code_info(&self) -> Option<String>

Return code metadata for inline or fenced code.

Inline code metadata is its language token. Fenced code metadata is reconstructed from lang and meta when either is present.

Source

pub fn extract_children(&mut self) -> Option<Node>

Take all direct children from this node and return them in a fragment.

Returns None for nodes that cannot contain children. The extracted child nodes retain their own positions; the new fragment has no source position of its own.

Source

pub fn render_with<R: Renderer>(&self, renderer: &mut R) -> String

Render this node with a user-provided renderer.

Source

pub fn to_markdown(&self) -> String

Serialize this AST node or fragment as Markdown.

Markdown output ends with a newline. For custom formatting, use to_markdown_with_options.

§Example
ⓘ
let markdown = node.to_markdown();
Source

pub fn to_markdown_with_options( &self, options: &Options, ) -> Result<String, Message>

Serialize this AST node or fragment as Markdown with custom options.

§Errors

Returns an error if an option contains an invalid marker or the AST contains a node that cannot be serialized.

Source

pub fn replace_heading_section( &mut self, heading_index: usize, replacement: Vec<Node>, replace_heading: bool, remove_subsections: bool, ) -> bool

Replace a heading and the section below it in this node’s children.

heading_index is the direct-child index of the heading. When replace_heading is false, the heading stays and only its section content is replaced. When remove_subsections is true, nested heading sections are included through the next heading of the same or higher level. Returns false if the index is not a heading.

Trait Implementations§

Source§

impl Clone for Node

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 Node

Source§

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

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

impl Eq for Node

Source§

impl PartialEq for Node

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 Node

Source§

impl ToString for Node

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more

Auto Trait Implementations§

§

impl Freeze for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

§

impl UnwindSafe for Node

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.