From cd5bb2d16c6b28332b0b6077b27b2b90a8051896 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 6 Oct 2022 15:57:55 +0200 Subject: Refactor to split parse from compile options --- readme.md | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'readme.md') diff --git a/readme.md b/readme.md index 91b7985..1afce35 100644 --- a/readme.md +++ b/readme.md @@ -92,17 +92,14 @@ Extensions (in this case GFM): ```rs extern crate micromark; -use micromark::{micromark_with_options, Constructs, Options}; +use micromark::{micromark_with_options, Options}; fn main() -> Result<(), String> { println!( "{}", micromark_with_options( "* [x] contact@example.com ~~strikethrough~~", - &Options { - constructs: Constructs::gfm(), - ..Options::default() - } + &Options::gfm() )? ); @@ -122,6 +119,29 @@ Yields: ``` +Syntax tree: + +```rs +extern crate micromark; +use micromark::{micromark_to_mdast, ParseOptions}; + +fn main() -> Result<(), String> { + println!( + "{:?}", + micromark_to_mdast("# Hey, *you*!", &ParseOptions::default())? + ); + + Ok(()) +} +``` + +Yields: + +```text +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)) } + +``` + ## API `micromark` exposes -- cgit