use std::{io::BufWriter, path::Path}; use pulldown_cmark::{Options, Parser}; pub fn compile_markdown( src: impl AsRef, html: impl AsRef, gmi: impl AsRef, ) -> std::io::Result<()> { let src_text = std::fs::read_to_string(src)?; let html = create_file(html)?; let gmi = create_file(gmi)?; for event in Parser::new_ext(&src_text, Options::all()) { use pulldown_cmark::Event::*; match event { Start(tag) => { use pulldown_cmark::Tag::*; println!("{tag:?}"); } End(tag) => { use pulldown_cmark::Tag::*; println!("{tag:?}"); } Text(text) => { println!("!{text}!"); } Code(code) => { println!("`{code}`"); } SoftBreak => {} HardBreak => { println!("
"); } Rule => { println!("------"); } TaskListMarker(state) => { println!("[{state}] task"); } other => { eprintln!("Unsupported markdown event: {:?}", other); } } } Ok(()) } #[inline(always)] fn create_file(path: impl AsRef) -> std::io::Result> { let f = std::fs::OpenOptions::new() .create(true) .write(true) .open(path)?; Ok(BufWriter::new(f)) }