1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
use color_eyre::{eyre::Context, Result};
use comrak::{format_html, nodes::AstNode, parse_document, Arena, ComrakOptions};
pub fn render(inp: &str) -> Result<String> {
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(())
}
|