diff options
Diffstat (limited to 'code/src/markdown/render.rs')
-rw-r--r-- | code/src/markdown/render.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/code/src/markdown/render.rs b/code/src/markdown/render.rs index 39f204f..f6b7686 100644 --- a/code/src/markdown/render.rs +++ b/code/src/markdown/render.rs @@ -15,7 +15,10 @@ pub fn span_to_html(ss: Vec<Span>) -> String { Span::Image(_, _) => todo!(), Span::Emphasis(c) => format!("<i>{}</i>", span_to_html(c)), Span::Strong(c) => format!("<b>{}</b>", span_to_html(c)), - Span::Latex(_) => format!("TODO: Inline Latex"), + Span::Latex(s) => fix_katex( + &katex::render_with_opts(&s, &katex::OptsBuilder::default().build().unwrap()) + .unwrap(), + ), } .as_str() } @@ -55,7 +58,16 @@ pub fn blocks_to_html(blocks: Vec<Block>) -> String { } Block::Raw(r) => r, Block::Hr => format!("<hr/>"), - Block::LatexBlock(_) => format!("TODO: Latex block"), + Block::LatexBlock(s) => fix_katex( + &katex::render_with_opts( + &s, + &katex::OptsBuilder::default() + .display_mode(true) + .build() + .unwrap(), + ) + .unwrap(), + ), } .as_str(); } @@ -69,3 +81,12 @@ pub fn escape(text: &str) -> String { .replace("'", "’") .replace("\"", """) } + +// TODO this is *really* bad fix +fn fix_katex<'a>(s: &str) -> String { + let e = s.find("<span class=\"katex-html\"").unwrap(); + s[0..e].replace( + "<mspace linebreak=\"newline\"></mspace>", + "</mrow></semantics></math><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow>", + ) +} |