Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,029 changes: 2,029 additions & 0 deletions resources/mermaid.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ pub const APP_NAME: &str = "Markdown to HTML Converter";
pub const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
const CARGO_PKG_AUTHORS: &str = env!("CARGO_PKG_AUTHORS");

const AFTER_HELP: &str = "Enjoy it! https://magiclen.org";
const AFTER_HELP: &str = "Enjoy it!";

const APP_ABOUT: &str = concat!(
"A simple tool for converting Simple Chinese to Traditional Chinese(TW).\n\nEXAMPLES:\n",
"A tool for converting markdown to html.\n\nEXAMPLES:\n",
concat_line!(prefix "markdown2html-converter ",
"/path/to/file.md # Convert /path/to/file.md to /path/to/file.html, titled \"file\"",
"/path/to/file.md -o /path/to/output.html # Convert /path/to/file.md to /path/to/output.html, titled \"output\"",
Expand Down
23 changes: 23 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ lazy_static_include_str! {
MATH_JAX => "resources/mathjax.min.js",
MATH_JAX_CONFIG => "resources/mathjax-config.js",
HIGHLIGHT => "resources/highlight.min.js",
MERMAID_CONFIG => "resources/mermaid.min.js",
}

fn main() -> anyhow::Result<()> {
Expand Down Expand Up @@ -141,6 +142,14 @@ fn main() -> anyhow::Result<()> {
}
};

let has_mermaid = {
if args.no_highlight {
false
} else {
markdown_html.contains("<code class=\"language-mermaid\">")
}
};

let has_mathjax = {
if args.no_mathjax {
false
Expand Down Expand Up @@ -223,6 +232,20 @@ fn main() -> anyhow::Result<()> {
html_minifier.digest(&markdown_html).unwrap();
html_minifier.digest("</article>").unwrap();

if has_mermaid {
html_minifier.digest("<script>").unwrap();
unsafe {
html_minifier.indigest(*MERMAID_CONFIG);
}
html_minifier.digest("
document.querySelectorAll('code[class^=\"language-mermaid\"]').forEach(function(element) {
var c = element.getAttribute('class');
element.setAttribute('class', c.replace(/language-mermaid/g, 'mermaid'));
});
mermaid.initialize({startOnLoad: true});
</script>").unwrap();
}

if !args.no_cjk_fonts {
html_minifier.digest("<script>").unwrap();
html_minifier.digest(*WEBFONT).unwrap();
Expand Down