From 802efbca25cb92d8567761361b6513fd57e05578 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 30 Aug 2022 16:54:57 +0200 Subject: basic syntax highlighting --- code/src/markdown.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'code/src/markdown.rs') 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) -> String { let mut out = String::new(); @@ -28,8 +29,12 @@ pub fn blocks_to_html(blocks: Vec) -> String { } Block::Paragraph(p) => format!("

{}

", span_to_html(p)), Block::Blockquote(q) => format!("{}", blocks_to_html(q)), - Block::CodeBlock(_syntax, content) => { - format!("
{}
", escape(&content)) // TODO syntax highlighting + Block::CodeBlock(syntax, content) => { + if let Some(s) = &syntax { + format!("
{}
", syntax_highlight(s, &content)) + } else { + format!("
{}
", escape(&content)) + } } Block::OrderedList(els, _) => format!( "
    {}
", @@ -74,4 +79,3 @@ pub fn escape(text: &str) -> String { .replace("'", "’") .replace("\"", """) } - -- cgit v1.2.3-70-g09d2