Node

Enum Node 

Source
pub enum Node {
Show 25 variants Document(Vec<Node>), ThematicBreak, Heading { level: u8, content: Vec<Node>, heading_type: HeadingType, }, CodeBlock { language: Option<EcoString>, content: EcoString, block_type: CodeBlockType, }, HtmlBlock(EcoString), LinkReferenceDefinition { label: EcoString, destination: EcoString, title: Option<EcoString>, }, Paragraph(Vec<Node>), BlockQuote(Vec<Node>), OrderedList { start: u32, items: Vec<ListItem>, }, UnorderedList(Vec<ListItem>), Table { headers: Vec<Node>, rows: Vec<Vec<Node>>, }, InlineCode(EcoString), Emphasis(Vec<Node>), Strong(Vec<Node>), Strikethrough(Vec<Node>), Link { url: EcoString, title: Option<EcoString>, content: Vec<Node>, }, ReferenceLink { label: EcoString, content: Vec<Node>, }, Image { url: EcoString, title: Option<EcoString>, alt: Vec<Node>, }, Autolink { url: EcoString, is_email: bool, }, ExtendedAutolink(EcoString), HtmlElement(HtmlElement), HardBreak, SoftBreak, Text(EcoString), Custom(Box<dyn CustomNode>),
}
Expand description

Main node type, representing an element in a CommonMark document

Variants§

§

Document(Vec<Node>)

Root document node, contains child nodes

§

ThematicBreak

Thematic break (horizontal rule)

§

Heading

Heading, contains level (1-6) and inline content

Fields

§level: u8

Heading level, 1-6

§content: Vec<Node>

Heading content, containing inline elements

§heading_type: HeadingType

Heading type (ATX or Setext)

§

CodeBlock

Code block, containing optional language identifier and content

Fields

§language: Option<EcoString>

Optional language identifier (None for indented code blocks, Some for fenced code blocks)

§content: EcoString

Code content

§block_type: CodeBlockType

The type of code block (Indented or Fenced)

§

HtmlBlock(EcoString)

HTML block

§

LinkReferenceDefinition

Link reference definition

Fields

§label: EcoString

Link label (used for reference)

§destination: EcoString

Link destination URL

§title: Option<EcoString>

Optional link title

§

Paragraph(Vec<Node>)

Paragraph node, containing inline elements

§

BlockQuote(Vec<Node>)

Block quote, containing any block-level elements

§

OrderedList

Ordered list, containing starting number and list items

Fields

§start: u32

List starting number

§items: Vec<ListItem>

List items

§

UnorderedList(Vec<ListItem>)

Unordered list, containing list items

§

Table

Table (extension to CommonMark)

Fields

§headers: Vec<Node>

Header cells

§rows: Vec<Vec<Node>>

Table rows, each row containing multiple cells

§

InlineCode(EcoString)

Inline code

§

Emphasis(Vec<Node>)

Emphasis (italic)

§

Strong(Vec<Node>)

Strong emphasis (bold)

§

Strikethrough(Vec<Node>)

Strikethrough (GFM extension)

Link

Fields

§url: EcoString

Link URL

§title: Option<EcoString>

Optional link title

§content: Vec<Node>

Link text

Reference link

Fields

§label: EcoString

Link reference label

§content: Vec<Node>

Link text content (optional, if empty it’s a shortcut reference)

§

Image

Image

Fields

§url: EcoString

Image URL

§title: Option<EcoString>

Optional image title

§alt: Vec<Node>

Alternative text, containing inline elements

Autolink (URI or email wrapped in < and >)

Fields

§url: EcoString

Link URL

§is_email: bool

Whether this is an email autolink

GFM Extended Autolink (without angle brackets, automatically detected)

§

HtmlElement(HtmlElement)

HTML inline element

§

HardBreak

Hard break (two spaces followed by a line break, or backslash followed by a line break)

§

SoftBreak

Soft break (single line break)

§

Text(EcoString)

Plain text

§

Custom(Box<dyn CustomNode>)

Custom node that allows users to implement their own writing behavior

Implementations§

Source§

impl Node

Source

pub fn is_block(&self) -> bool

Check if a node is a block-level node

Source

pub fn is_inline(&self) -> bool

Check if a node is an inline node

Source

pub fn heading(level: u8, content: Vec<Node>) -> Self

Create a heading node

§Arguments
  • level - Heading level (1-6)
  • content - Heading content
§Returns

A new heading node, default ATX type

Source

pub fn code_block(language: Option<EcoString>, content: EcoString) -> Self

Create a code block node

§Arguments
  • language - Optional language identifier
  • content - Code content
§Returns

A new code block node, default Fenced type

Source

pub fn strikethrough(content: Vec<Node>) -> Self

Create a strikethrough node

§Arguments
  • content - Content to be struck through
§Returns

A new strikethrough node

Source

pub fn as_custom_type<T: CustomNode + 'static>(&self) -> Option<&T>

Check if a custom node is of a specific type, and return a reference to that type

Source

pub fn is_custom_type<T: CustomNode + 'static>(&self) -> bool

Check if a node is a custom node of a specific type

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

Returns a duplicate of the value. Read more
1.0.0 · 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 PartialEq for Node

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Node

Auto Trait Implementations§

§

impl Freeze for Node

§

impl !RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin 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> 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 = 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.