aboutsummaryrefslogtreecommitdiff
path: root/code/src/markdown.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2022-08-30 16:54:57 +0200
committermetamuffin <metamuffin@disroot.org>2022-08-30 16:54:57 +0200
commit802efbca25cb92d8567761361b6513fd57e05578 (patch)
tree62eb0139143cc343d83d92091eee8efaf0888001 /code/src/markdown.rs
parented6186a764701e702032156c9632ac19305652be (diff)
downloadmetamuffin-blog-802efbca25cb92d8567761361b6513fd57e05578.tar
metamuffin-blog-802efbca25cb92d8567761361b6513fd57e05578.tar.bz2
metamuffin-blog-802efbca25cb92d8567761361b6513fd57e05578.tar.zst
basic syntax highlighting
Diffstat (limited to 'code/src/markdown.rs')
-rw-r--r--code/src/markdown.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/code/src/markdown.rs b/code/src/markdown.rs
index 5d98f83..22934c5 100644
--- a/code/src/markdown.rs
+++ b/code/src/markdown.rs
@@ -1,5 +1,6 @@
use markdown::{Block, ListItem, Span};
+use crate::syntax_highlight::syntax_highlight;
pub fn span_to_html(ss: Vec<Span>) -> String {
let mut out = String::new();
@@ -28,8 +29,12 @@ pub fn blocks_to_html(blocks: Vec<Block>) -> String {
}
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>", escape(&content)) // TODO syntax highlighting
+ Block::CodeBlock(syntax, content) => {
+ if let Some(s) = &syntax {
+ format!("<pre>{}</pre>", syntax_highlight(s, &content))
+ } else {
+ format!("<pre>{}</pre>", escape(&content))
+ }
}
Block::OrderedList(els, _) => format!(
"<ol>{}</ol>",
@@ -74,4 +79,3 @@ pub fn escape(text: &str) -> String {
.replace("'", "&#8217;")
.replace("\"", "&quot;")
}
-