Function markdown::to_mdast

source ·
pub fn to_mdast(value: &str, options: &ParseOptions) -> Result<Node, String>
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("# Hey, *you*!", &ParseOptions::default())?;

println!("{:?}", tree);
// => Root { children: [Heading { children: [Text { value: "Hey, ", position: Some(1:3-1:8 (2-7)) }, Emphasis { children: [Text { value: "you", position: Some(1:9-1:12 (8-11)) }], position: Some(1:8-1:13 (7-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)) }