use equt_md_ext::{error::Result, Event, MarkdownExt, Parser, Tag}; macro_rules! assert_events { ($iter:expr, $( $event:expr), *) => { $( assert_eq!($iter.next(), Some($event)); )* assert_eq!($iter.next(), None); }; } #[test] fn frontmatter_overwrite() -> Result<()> { let mut iter = Parser::new(include_str!("data/test.md"))? .after( |e| match &e { Event::End(Tag::Heading(1)) => true, _ => false, }, |fm| { vec![Event::Text( fm.as_ref() .and_then(|fm| Some(fm.title.clone())) .unwrap_or("Nothing".into()) .into(), )] }, ) .link(Parser::new(include_str!("data/frontmatter.md"))?.after( |e| match &e { Event::End(Tag::Heading(1)) => true, _ => false, }, |fm| { vec![Event::Text( fm.as_ref() .and_then(|fm| Some(fm.title.clone())) .unwrap_or("Nothing".into()) .into(), )] }, )); assert_events!( iter, Event::Start(Tag::Heading(1)), Event::Text("Heading".into()), Event::End(Tag::Heading(1)), Event::Text("FrontMatter".into()), Event::Start(Tag::Heading(1)), Event::Text("Heading".into()), Event::End(Tag::Heading(1)), Event::Text("FrontMatter".into()) ); Ok(()) }