to_mdast

Function to_mdast 

Source
pub fn to_mdast(value: &str, options: &ParseOptions) -> Result<Node, Message>
Expand description

Turn markdown into a syntax tree.

§Errors

to_mdast() never errors with normal markdown because markdown does not have syntax errors, so feel free to unwrap(). However, MDX does have syntax errors. When MDX is turned on, there are several errors that can occur with how JSX, expressions, or ESM are written.

§Examples

use markdown::{to_mdast, ParseOptions};

let tree = to_mdast("# Hi *Earth*!", &ParseOptions::default())?;

println!("{:?}", tree);
// => Root { children: [Heading { children: [Text { value: "Hi ", position: Some(1:3-1:6 (2-5)) }, Emphasis { children: [Text { value: "Earth", position: Some(1:7-1:12 (6-11)) }], position: Some(1:6-1:13 (5-12)) }, Text { value: "!", position: Some(1:13-1:14 (12-13)) }], position: Some(1:1-1:14 (0-13)), depth: 1 }], position: Some(1:1-1:14 (0-13)) }