From c4d7f8f50d53057005d6bb28ac487f69ea45bd5e Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Sun, 19 Dec 2021 12:48:36 -0500 Subject: Add blog post parsing and templates templates WIP, not building properly --- src/internal/markdown.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/internal/markdown.rs (limited to 'src/internal/markdown.rs') diff --git a/src/internal/markdown.rs b/src/internal/markdown.rs new file mode 100644 index 0000000..9798876 --- /dev/null +++ b/src/internal/markdown.rs @@ -0,0 +1,21 @@ +use color_eyre::{Result, eyre::Context}; +use comrak::{ComrakOptions, Arena, parse_document, format_html}; + + +pub fn render(inp: &str) -> Result { + let mut options = ComrakOptions::default(); + options.extension.autolink = true; + options.extension.table = true; + options.extension.superscript = true; + options.extension.footnotes = true; + + options.render.unsafe_ = 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") +} -- cgit v1.2.3