aboutsummaryrefslogtreecommitdiff
path: root/code/src/markdown/render.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2022-09-25 18:29:22 +0200
committermetamuffin <metamuffin@disroot.org>2022-09-25 18:29:22 +0200
commite3edf18503b3975ccec3b33c0cb9e7f0888bd031 (patch)
tree9b8d795bf5e0ff6e0f5cdd882cef07d495f73a72 /code/src/markdown/render.rs
parenta80b5c677417cdbc17df3109ef9d12afe79973cc (diff)
downloadmetamuffin-blog-e3edf18503b3975ccec3b33c0cb9e7f0888bd031.tar
metamuffin-blog-e3edf18503b3975ccec3b33c0cb9e7f0888bd031.tar.bz2
metamuffin-blog-e3edf18503b3975ccec3b33c0cb9e7f0888bd031.tar.zst
extend parser
Diffstat (limited to 'code/src/markdown/render.rs')
-rw-r--r--code/src/markdown/render.rs30
1 files changed, 10 insertions, 20 deletions
diff --git a/code/src/markdown/render.rs b/code/src/markdown/render.rs
index 22934c5..39f204f 100644
--- a/code/src/markdown/render.rs
+++ b/code/src/markdown/render.rs
@@ -1,7 +1,7 @@
-use markdown::{Block, ListItem, Span};
-
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 {
@@ -9,12 +9,13 @@ pub fn span_to_html(ss: Vec<Span>) -> String {
Span::Break => format!("<br/>"),
Span::Text(t) => escape(&t),
Span::Code(c) => format!("<code>{}</code>", escape(&c)),
- Span::Link(text, url, _) => {
+ Span::Link(text, url) => {
format!("<a href=\"{}\">{}</a>", escape(&url), escape(&text))
}
- Span::Image(_, _, _) => todo!(),
+ 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"),
}
.as_str()
}
@@ -24,7 +25,7 @@ pub fn blocks_to_html(blocks: Vec<Block>) -> String {
let mut out = String::new();
for e in blocks {
out += match e {
- Block::Header(text, level) => {
+ Block::Header(level, text) => {
format!("<h{level}>{}</h{level}>", span_to_html(text))
}
Block::Paragraph(p) => format!("<p>{}</p>", span_to_html(p)),
@@ -36,16 +37,10 @@ pub fn blocks_to_html(blocks: Vec<Block>) -> String {
format!("<pre>{}</pre>", escape(&content))
}
}
- Block::OrderedList(els, _) => format!(
+ Block::OrderedList(els) => format!(
"<ol>{}</ol>",
els.into_iter()
- .map(|e| format!(
- "<li>{}</li>",
- match e {
- ListItem::Simple(s) => span_to_html(s),
- ListItem::Paragraph(b) => blocks_to_html(b),
- }
- ))
+ .map(|e| format!("<li>{}</li>", blocks_to_html(e)))
.collect::<Vec<_>>()
.join("")
),
@@ -53,19 +48,14 @@ pub fn blocks_to_html(blocks: Vec<Block>) -> String {
format!(
"<ul>{}</ul>",
els.into_iter()
- .map(|e| format!(
- "<li>{}</li>",
- match e {
- ListItem::Simple(s) => span_to_html(s),
- ListItem::Paragraph(b) => blocks_to_html(b),
- }
- ))
+ .map(|e| format!("<li>{}</li>", blocks_to_html(e)))
.collect::<Vec<_>>()
.join("")
)
}
Block::Raw(r) => r,
Block::Hr => format!("<hr/>"),
+ Block::LatexBlock(_) => format!("TODO: Latex block"),
}
.as_str();
}