use color_eyre::{eyre::Context, Result}; use comrak::{format_html, nodes::AstNode, parse_document, Arena, ComrakOptions}; pub fn render(inp: &str) -> Result { let mut options = ComrakOptions::default(); options.extension.table = true; options.extension.description_lists = true; options.extension.strikethrough = true; options.extension.footnotes = true; let arena = Arena::new(); let root = parse_document(&arena, inp, &options); let mut html = vec![]; format_html(root, &options, &mut html).unwrap(); String::from_utf8(html).wrap_err("this is somehow not UTF-8") } /** * Takes in a root node and a function to act on it, then recursively acts on * all children of that node */ fn iter_nodes<'a, F>(node: &'a AstNode<'a>, f: &F) -> Result<()> where F: Fn(&'a AstNode<'a>) -> Result<()>, { f(node)?; for c in node.children() { iter_nodes(c, f)?; } Ok(()) }