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
34
35
use comrak::{markdown_to_html, ComrakOptions};
use gh_emoji;
mod template;

pub fn github_markdown_to_html(md: String, filename: String) -> String {
    let mut contents = String::from("");
    let options = set_opts();
    let markdown = markdown_to_html(&md, &options);
    let boilerplate = template::format_boilerplate(&filename);
    let css: &str = template::CSS;
    let footer: &str = template::FOOTER;
    contents.push_str(boilerplate.as_str());
    contents.push_str(css);
    contents.push_str(&markdown);
    contents.push_str(footer);
    // contents
    let replacer = gh_emoji::Replacer::new();
    let text = replacer.replace_all(&contents);
    text.to_string() 
}

fn set_opts() -> ComrakOptions {
    let mut options = ComrakOptions::default();
    options.unsafe_ = true;
    options.github_pre_lang = true;
    options.ext_table = true;
    options.ext_tagfilter = true;
    options.ext_strikethrough = true;
    options.ext_footnotes = true;
    options.ext_superscript = true;
    options.ext_autolink = true;
    options.ext_tasklist = true;
    options.ext_description_lists = true;
    options
}