Skip to main content

Node

Enum Node 

Source
pub enum Node {
Show 33 variants Blockquote(Blockquote), Break(Break), Definition(Definition), Delete(Delete), Heading(Heading), Emphasis(Emphasis), Footnote(Footnote), FootnoteRef(FootnoteRef), Html(Html), Yaml(Yaml), Toml(Toml), Image(Image), ImageRef(ImageRef), CodeInline(CodeInline), MathInline(MathInline), Link(Link), LinkRef(LinkRef), Math(Math), List(List), TableAlign(TableAlign), TableRow(TableRow), TableCell(TableCell), Code(Code), Strong(Strong), HorizontalRule(HorizontalRule), MdxFlowExpression(MdxFlowExpression), MdxJsxFlowElement(MdxJsxFlowElement), MdxJsxTextElement(MdxJsxTextElement), MdxTextExpression(MdxTextExpression), MdxJsEsm(MdxJsEsm), Text(Text), Fragment(Fragment), Empty,
}
Expand description

A Markdown node.

Variants§

§

Blockquote(Blockquote)

A block quote.

§

Break(Break)

A hard line break.

§

Definition(Definition)

A link reference definition.

§

Delete(Delete)

Strikethrough text.

§

Heading(Heading)

A heading.

§

Emphasis(Emphasis)

Emphasized text.

§

Footnote(Footnote)

A footnote definition.

§

FootnoteRef(FootnoteRef)

A footnote reference.

§

Html(Html)

Raw HTML.

§

Yaml(Yaml)

YAML front matter.

§

Toml(Toml)

TOML front matter.

§

Image(Image)

An inline image.

§

ImageRef(ImageRef)

A reference-style image.

§

CodeInline(CodeInline)

Inline code.

§

MathInline(MathInline)

Inline math.

An inline link.

§

LinkRef(LinkRef)

A reference-style link.

§

Math(Math)

A math block.

§

List(List)

A list item.

§

TableAlign(TableAlign)

The delimiter row of a table, giving the column alignments.

§

TableRow(TableRow)

A table row.

§

TableCell(TableCell)

A table cell.

§

Code(Code)

A code block.

§

Strong(Strong)

Strongly emphasized text.

§

HorizontalRule(HorizontalRule)

A thematic break.

§

MdxFlowExpression(MdxFlowExpression)

A block-level MDX expression.

§

MdxJsxFlowElement(MdxJsxFlowElement)

A block-level JSX element.

§

MdxJsxTextElement(MdxJsxTextElement)

An inline JSX element.

§

MdxTextExpression(MdxTextExpression)

An inline MDX expression.

§

MdxJsEsm(MdxJsEsm)

MDX ESM import or export.

§

Text(Text)

Plain text.

§

Fragment(Fragment)

A sequence of nodes with no wrapper.

§

Empty

An empty node.

Implementations§

Source§

impl Node

Source

pub fn attr(&self, attr: &str) -> Option<AttrValue>

Returns the value of the specified attribute, if present.

line/end_line are handled here, not per-variant below, since position is common to every node.

Source

pub fn set_attr( &mut self, attr: &str, value: impl Into<AttrValue>, ) -> Result<(), SetAttrError>

Sets the value of the specified attribute for the node.

Fails when the node has no settable attribute attr or value does not fit it. A heading depth outside of 1 to 6 is clamped.

Source§

impl Node

Source

pub fn to_string_with(&self, options: &RenderOptions) -> String

Writes the node as Markdown with the given options.

Source§

impl Node

Source

pub fn map_values<E, F>(&self, f: &mut F) -> Result<Node, E>
where E: Error, F: FnMut(&Node) -> Result<Node, E>,

Maps this node and its fragment descendants, cloning the input tree first.

Source

pub fn map_values_into<E, F>(self, f: &mut F) -> Result<Node, E>
where E: Error, F: FnMut(&Node) -> Result<Node, E>,

Maps this node and its fragment descendants, consuming the input tree.

Prefer this over Self::map_values when the caller owns the node and does not need to retain an unchanged copy.

Source

pub fn map_values_into_owned<E, F>(self, f: &mut F) -> Result<Node, E>
where E: Error, F: FnMut(Node) -> Result<Node, E>,

Maps this node and its fragment descendants, giving the callback ownership of each node.

This is useful when a transform must retain an unchanged fallback node without cloning it again after the callback returns. The traversal continues through a fragment returned by the callback, matching Self::map_values_into’s behavior.

Source

pub fn to_fragment(&self) -> Node

Converts a clone of this node into a fragment of its children.

Source

pub fn into_fragment(self) -> Node

Converts this node into a fragment, preserving its children without cloning them.

Leaf nodes become Node::Empty. This is the consuming counterpart to Self::to_fragment.

Source

pub fn apply_fragment(&mut self, fragment: Node)

Replaces the children of this node with those of fragment.

Source

pub fn node_values(&self) -> Vec<Node>

Returns the child nodes, or the node itself if it has none.

Source

pub fn find_at_index(&self, index: usize) -> Option<Node>

Returns the child at index, if any.

Source

pub fn value(&self) -> String

Returns the text content of the node.

Source

pub fn name(&self) -> SmolStr

Returns the node name, such as "heading" or "code".

Source

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

Get the children nodes of the current node.

Source

pub fn set_children(&mut self, children: Vec<Node>)

Sets the children nodes of the current node, if the node supports children. Nodes without children (e.g. Text, Code, Image) are left unchanged.

Source

pub fn set_position(&mut self, pos: Option<Position>)

Sets the position of the node.

Source

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

Returns the position of the node, if known.

Source

pub fn strip_positions(&mut self)

Recursively clears position information from this node and all of its children. Useful for shrinking structured output (JSON, YAML, etc.) when source spans aren’t needed, since Position accounts for most of a serialized node’s size.

Source

pub fn clear_text_position_at(&mut self, index: usize)

Clears the position of just the Text leaf that into_with_value / into_with_children_value would write into at index, leaving this node and other descendants untouched. Used to stop the renderer re-escaping an already-escaped leaf.

Source

pub fn is_empty(&self) -> bool

Returns true if this node is empty.

Source

pub fn is_fragment(&self) -> bool

Returns true if this node is a fragment.

Source

pub fn is_empty_fragment(&self) -> bool

Returns true if this node is a fragment with no nodes.

Source

pub fn is_inline_code(&self) -> bool

Returns true if this node is inline code.

Source

pub fn is_inline_math(&self) -> bool

Returns true if this node is inline math.

Source

pub fn is_strong(&self) -> bool

Returns true if this node is strongly emphasized text.

Source

pub fn is_list(&self) -> bool

Returns true if this node is a list item.

Source

pub fn is_emphasis(&self) -> bool

Returns true if this node is emphasized text.

Source

pub fn is_delete(&self) -> bool

Returns true if this node is a strikethrough.

Returns true if this node is a link.

Returns true if this node is a reference-style link.

Source

pub fn is_text(&self) -> bool

Returns true if this node is a text node.

Source

pub fn is_image(&self) -> bool

Returns true if this node is an image.

Source

pub fn is_horizontal_rule(&self) -> bool

Returns true if this node is a thematic break.

Source

pub fn is_blockquote(&self) -> bool

Returns true if this node is a block quote.

Source

pub fn is_html(&self) -> bool

Returns true if this node is a raw HTML node.

Source

pub fn is_footnote(&self) -> bool

Returns true if this node is a footnote definition.

Source

pub fn is_mdx_jsx_flow_element(&self) -> bool

Returns true if this node is a block-level JSX element.

Source

pub fn is_mdx_js_esm(&self) -> bool

Returns true if this node is an MDX ESM statement.

Source

pub fn is_toml(&self) -> bool

Returns true if this node is TOML front matter.

Source

pub fn is_yaml(&self) -> bool

Returns true if this node is YAML front matter.

Source

pub fn is_break(&self) -> bool

Returns true if this node is a hard line break.

Source

pub fn is_mdx_text_expression(&self) -> bool

Returns true if this node is an inline MDX expression.

Source

pub fn is_footnote_ref(&self) -> bool

Returns true if this node is a footnote reference.

Source

pub fn is_image_ref(&self) -> bool

Returns true if this node is a reference-style image.

Source

pub fn is_mdx_jsx_text_element(&self) -> bool

Returns true if this node is an inline JSX element.

Source

pub fn is_math(&self) -> bool

Returns true if this node is a math block.

Source

pub fn is_mdx_flow_expression(&self) -> bool

Returns true if this node is a block-level MDX expression.

Source

pub fn is_definition(&self) -> bool

Returns true if this node is a link reference definition.

Source

pub fn is_table_align(&self) -> bool

Returns true if this node is a table delimiter row.

Source

pub fn is_code(&self, lang: Option<SmolStr>) -> bool

Returns true if this node is a code block, of language lang when given.

Source

pub fn is_heading(&self, depth: Option<u8>) -> bool

Returns true if this node is a heading, of depth depth when given.

Source

pub fn with_value(&self, value: &str) -> Self

Returns a clone of this node with its value replaced.

Source

pub fn into_with_value(self, value: &str) -> Self

Replaces this node’s value while consuming the original tree.

Prefer this over Self::with_value when the caller owns the node and does not need an unchanged copy.

Source

pub fn with_children_value(&self, value: &str, index: usize) -> Self

Returns a clone of this node with the selected child’s value replaced.

Source

pub fn into_with_children_value(self, value: &str, index: usize) -> Self

Replaces a selected child’s value while consuming the original tree.

Prefer this over Self::with_children_value when the caller owns the node and does not need an unchanged copy.

Source§

impl Node

Source

pub fn kind(&self) -> NodeKind

The kind of this node. A heading depth outside 1..=6, which parsing never produces, is clamped.

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 Default for Node

Source§

fn default() -> Self

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

impl Display for Node

Source§

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

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

impl From<&str> for Node

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Node

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
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 PartialOrd for Node

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

§

impl Forget for Node

§

impl Freeze for Node

§

impl Move 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.