aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2022-09-26 17:50:37 +0200
committermetamuffin <metamuffin@disroot.org>2022-09-26 17:50:37 +0200
commitf66078941b036bc87636620c64aeab8802fd4a5b (patch)
tree848e148b419f6214246d239f6f5886002a0bcbac
parenta86d83a46471ec3d953cb082d35d25bc1d58dfab (diff)
downloadmetamuffin-blog-f66078941b036bc87636620c64aeab8802fd4a5b.tar
metamuffin-blog-f66078941b036bc87636620c64aeab8802fd4a5b.tar.bz2
metamuffin-blog-f66078941b036bc87636620c64aeab8802fd4a5b.tar.zst
delete old renderer
-rw-r--r--code/src/markdown/render.rs84
1 files changed, 0 insertions, 84 deletions
diff --git a/code/src/markdown/render.rs b/code/src/markdown/render.rs
deleted file mode 100644
index 75ebe43..0000000
--- a/code/src/markdown/render.rs
+++ /dev/null
@@ -1,84 +0,0 @@
-use crate::syntax_highlight::syntax_highlight;
-
-use super::parser::{Block, Span};
-
-pub fn span_to_html(ss: Vec<Span>) -> String {
- let mut out = String::new();
- for s in ss {
- out += match s {
- Span::Break => format!("<br/>"),
- Span::Text(t) => escape(&t),
- Span::Code(c) => format!("<code>{}</code>", escape(&c)),
- Span::Link(text, url) => {
- format!("<a href=\"{}\">{}</a>", escape(&url), escape(&text))
- }
- 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(s) => fix_katex(
- &katex::render_with_opts(&s, &katex::OptsBuilder::default().build().unwrap())
- .unwrap(),
- ),
- }
- .as_str()
- }
- out
-}
-pub fn blocks_to_html(blocks: Vec<Block>) -> String {
- let mut out = String::new();
- for e in blocks {
- out += match e {
- Block::Header(level, text) => {
- format!("<h{level}>{}</h{level}>", span_to_html(text))
- }
- Block::Paragraph(p) => format!("<p>{}</p>", span_to_html(p)),
- Block::Blockquote(q) => format!("<quote>{}</quote>", blocks_to_html(q)),
- Block::CodeBlock(syntax, content) => {
- format!(
- "<pre>{}</pre>",
- syntax_highlight(&syntax.unwrap_or(String::from("")), &content)
- .unwrap_or_else(|| escape(&content))
- )
- }
- Block::OrderedList(els) => format!(
- "<ol>{}</ol>",
- els.into_iter()
- .map(|e| format!("<li>{}</li>", blocks_to_html(e)))
- .collect::<Vec<_>>()
- .join("")
- ),
- Block::UnorderedList(els) => {
- format!(
- "<ul>{}</ul>",
- els.into_iter()
- .map(|e| format!("<li>{}</li>", blocks_to_html(e)))
- .collect::<Vec<_>>()
- .join("")
- )
- }
- Block::Raw(r) => r,
- Block::Hr => format!("<hr/>"),
- Block::LatexBlock(s) => fix_katex(
- &katex::render_with_opts(
- &s,
- &katex::OptsBuilder::default()
- .display_mode(true)
- .build()
- .unwrap(),
- )
- .unwrap(),
- ),
- }
- .as_str();
- }
- out
-}
-
-// 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>",
- )
-}