diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-09-26 16:12:25 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-09-26 16:12:25 +0200 |
commit | a0c84c505d733be2e987a333a34244c1befb56cb (patch) | |
tree | 0545a747b6f2f627a71bd31949ad622bbc56c176 /src/lib.rs | |
parent | 9cb9e37c33173c16cbafd345f43e43b5a550537d (diff) | |
download | markdown-rs-a0c84c505d733be2e987a333a34244c1befb56cb.tar.gz markdown-rs-a0c84c505d733be2e987a333a34244c1befb56cb.tar.bz2 markdown-rs-a0c84c505d733be2e987a333a34244c1befb56cb.zip |
Add support for compiling to mdast
See: <https://github.com/syntax-tree/mdast>.
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 30 |
1 files changed, 16 insertions, 14 deletions
@@ -28,7 +28,7 @@ mod tokenizer; mod util; use alloc::{boxed::Box, fmt, string::String}; -use mdast::Root; +use mdast::Node; use parser::parse; use to_html::compile as to_html; use to_mdast::compile as to_mdast; @@ -1082,19 +1082,11 @@ impl fmt::Debug for Options { .field("math_text_single_dollar", &self.math_text_single_dollar) .field( "mdx_expression_parse", - if self.mdx_expression_parse.is_none() { - &"None" - } else { - &"Some([Function])" - }, + &self.mdx_expression_parse.as_ref().map(|_d| "[Function]"), ) .field( "mdx_esm_parse", - if self.mdx_esm_parse.is_none() { - &"None" - } else { - &"Some([Function])" - }, + &self.mdx_esm_parse.as_ref().map(|_d| "[Function]"), ) .finish() } @@ -1180,8 +1172,18 @@ pub fn micromark_with_options(value: &str, options: &Options) -> Result<String, /// /// ## Examples /// -/// To do. -pub fn micromark_to_mdast(value: &str, options: &Options) -> Result<Root, String> { +/// ``` +/// use micromark::{micromark_to_mdast, Options}; +/// # fn main() -> Result<(), String> { +/// +/// let tree = micromark_to_mdast("# hi!", &Options::default())?; +/// +/// println!("{:?}", tree); +/// # Ok(()) +/// # } +/// ``` +pub fn micromark_to_mdast(value: &str, options: &Options) -> Result<Node, String> { let (events, bytes) = parse(value, options)?; - Ok(to_mdast(&events, bytes, options)) + let node = to_mdast(&events, bytes)?; + Ok(node) } |