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.
Link(Link)
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
impl Node
Source§impl Node
impl Node
Sourcepub fn to_string_with(&self, options: &RenderOptions) -> String
pub fn to_string_with(&self, options: &RenderOptions) -> String
Writes the node as Markdown with the given options.
Source§impl Node
impl Node
Sourcepub fn map_values<E, F>(&self, f: &mut F) -> Result<Node, E>
pub fn map_values<E, F>(&self, f: &mut F) -> Result<Node, E>
Maps this node and its fragment descendants, cloning the input tree first.
Sourcepub fn map_values_into<E, F>(self, f: &mut F) -> Result<Node, E>
pub fn map_values_into<E, F>(self, f: &mut F) -> 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.
Sourcepub fn map_values_into_owned<E, F>(self, f: &mut F) -> Result<Node, E>
pub fn map_values_into_owned<E, F>(self, f: &mut F) -> 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.
Sourcepub fn to_fragment(&self) -> Node
pub fn to_fragment(&self) -> Node
Converts a clone of this node into a fragment of its children.
Sourcepub fn into_fragment(self) -> Node
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.
Sourcepub fn apply_fragment(&mut self, fragment: Node)
pub fn apply_fragment(&mut self, fragment: Node)
Replaces the children of this node with those of fragment.
Sourcepub fn node_values(&self) -> Vec<Node>
pub fn node_values(&self) -> Vec<Node>
Returns the child nodes, or the node itself if it has none.
Sourcepub fn find_at_index(&self, index: usize) -> Option<Node>
pub fn find_at_index(&self, index: usize) -> Option<Node>
Returns the child at index, if any.
Sourcepub fn set_children(&mut self, children: Vec<Node>)
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.
Sourcepub fn set_position(&mut self, pos: Option<Position>)
pub fn set_position(&mut self, pos: Option<Position>)
Sets the position of the node.
Sourcepub fn strip_positions(&mut self)
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.
Sourcepub fn clear_text_position_at(&mut self, index: usize)
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.
Sourcepub fn is_fragment(&self) -> bool
pub fn is_fragment(&self) -> bool
Returns true if this node is a fragment.
Sourcepub fn is_empty_fragment(&self) -> bool
pub fn is_empty_fragment(&self) -> bool
Returns true if this node is a fragment with no nodes.
Sourcepub fn is_inline_code(&self) -> bool
pub fn is_inline_code(&self) -> bool
Returns true if this node is inline code.
Sourcepub fn is_inline_math(&self) -> bool
pub fn is_inline_math(&self) -> bool
Returns true if this node is inline math.
Sourcepub fn is_emphasis(&self) -> bool
pub fn is_emphasis(&self) -> bool
Returns true if this node is emphasized text.
Sourcepub fn is_link_ref(&self) -> bool
pub fn is_link_ref(&self) -> bool
Returns true if this node is a reference-style link.
Sourcepub fn is_horizontal_rule(&self) -> bool
pub fn is_horizontal_rule(&self) -> bool
Returns true if this node is a thematic break.
Sourcepub fn is_blockquote(&self) -> bool
pub fn is_blockquote(&self) -> bool
Returns true if this node is a block quote.
Sourcepub fn is_footnote(&self) -> bool
pub fn is_footnote(&self) -> bool
Returns true if this node is a footnote definition.
Sourcepub fn is_mdx_jsx_flow_element(&self) -> bool
pub fn is_mdx_jsx_flow_element(&self) -> bool
Returns true if this node is a block-level JSX element.
Sourcepub fn is_mdx_js_esm(&self) -> bool
pub fn is_mdx_js_esm(&self) -> bool
Returns true if this node is an MDX ESM statement.
Sourcepub fn is_mdx_text_expression(&self) -> bool
pub fn is_mdx_text_expression(&self) -> bool
Returns true if this node is an inline MDX expression.
Sourcepub fn is_footnote_ref(&self) -> bool
pub fn is_footnote_ref(&self) -> bool
Returns true if this node is a footnote reference.
Sourcepub fn is_image_ref(&self) -> bool
pub fn is_image_ref(&self) -> bool
Returns true if this node is a reference-style image.
Sourcepub fn is_mdx_jsx_text_element(&self) -> bool
pub fn is_mdx_jsx_text_element(&self) -> bool
Returns true if this node is an inline JSX element.
Sourcepub fn is_mdx_flow_expression(&self) -> bool
pub fn is_mdx_flow_expression(&self) -> bool
Returns true if this node is a block-level MDX expression.
Sourcepub fn is_definition(&self) -> bool
pub fn is_definition(&self) -> bool
Returns true if this node is a link reference definition.
Sourcepub fn is_table_align(&self) -> bool
pub fn is_table_align(&self) -> bool
Returns true if this node is a table delimiter row.
Sourcepub fn is_code(&self, lang: Option<SmolStr>) -> bool
pub fn is_code(&self, lang: Option<SmolStr>) -> bool
Returns true if this node is a code block, of language lang when given.
Sourcepub fn is_heading(&self, depth: Option<u8>) -> bool
pub fn is_heading(&self, depth: Option<u8>) -> bool
Returns true if this node is a heading, of depth depth when given.
Sourcepub fn with_value(&self, value: &str) -> Self
pub fn with_value(&self, value: &str) -> Self
Returns a clone of this node with its value replaced.
Sourcepub fn into_with_value(self, value: &str) -> Self
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.
Sourcepub fn with_children_value(&self, value: &str, index: usize) -> Self
pub fn with_children_value(&self, value: &str, index: usize) -> Self
Returns a clone of this node with the selected child’s value replaced.
Sourcepub fn into_with_children_value(self, value: &str, index: usize) -> Self
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.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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