summaryrefslogtreecommitdiff
path: root/src/internal/markdown.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/internal/markdown.rs')
-rw-r--r--src/internal/markdown.rs33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/internal/markdown.rs b/src/internal/markdown.rs
index 1538d11..9d0d0b9 100644
--- a/src/internal/markdown.rs
+++ b/src/internal/markdown.rs
@@ -1,28 +1,33 @@
-use color_eyre::{Result, eyre::Context};
-use comrak::{ComrakOptions, Arena, parse_document, format_html, markdown_to_html};
-
+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.autolink = true;
options.extension.table = true;
options.extension.description_lists = true;
- options.extension.superscript = true;
options.extension.strikethrough = true;
options.extension.footnotes = true;
- options.render.unsafe_ = true;
-
- info!("{:?}", options.clone());
- info!("{:?}", inp.clone());
+ let arena = Arena::new();
+ let root = parse_document(&arena, inp, &options);
- Ok(markdown_to_html(inp, &options))
-/*
let mut html = vec![];
format_html(root, &options, &mut html).unwrap();
- info!("{:?}", String::from_utf8(html.clone()));
-
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(())
}