From f66078941b036bc87636620c64aeab8802fd4a5b Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 26 Sep 2022 17:50:37 +0200 Subject: delete old renderer --- code/src/markdown/render.rs | 84 --------------------------------------------- 1 file changed, 84 deletions(-) delete mode 100644 code/src/markdown/render.rs (limited to 'code/src') 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) -> String { - let mut out = String::new(); - for s in ss { - out += match s { - Span::Break => format!("
"), - Span::Text(t) => escape(&t), - Span::Code(c) => format!("{}", escape(&c)), - Span::Link(text, url) => { - format!("{}", escape(&url), escape(&text)) - } - Span::Image(_, _) => todo!(), - Span::Emphasis(c) => format!("{}", span_to_html(c)), - Span::Strong(c) => format!("{}", 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) -> String { - let mut out = String::new(); - for e in blocks { - out += match e { - Block::Header(level, text) => { - format!("{}", span_to_html(text)) - } - Block::Paragraph(p) => format!("

{}

", span_to_html(p)), - Block::Blockquote(q) => format!("{}", blocks_to_html(q)), - Block::CodeBlock(syntax, content) => { - format!( - "
{}
", - syntax_highlight(&syntax.unwrap_or(String::from("")), &content) - .unwrap_or_else(|| escape(&content)) - ) - } - Block::OrderedList(els) => format!( - "
    {}
", - els.into_iter() - .map(|e| format!("
  • {}
  • ", blocks_to_html(e))) - .collect::>() - .join("") - ), - Block::UnorderedList(els) => { - format!( - "
      {}
    ", - els.into_iter() - .map(|e| format!("
  • {}
  • ", blocks_to_html(e))) - .collect::>() - .join("") - ) - } - Block::Raw(r) => r, - Block::Hr => format!("
    "), - 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("", - "", - ) -} -- cgit v1.2.3-70-g09d2