From c46a61fba67b232ae1daabd151366f1f0c5cf7da Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 11 Apr 2023 01:20:11 +0200 Subject: [PATCH] add syntax highlight --- src/template.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/template.rs b/src/template.rs index ed154ab..df63f4d 100644 --- a/src/template.rs +++ b/src/template.rs @@ -51,6 +51,7 @@ pub struct FileMetadata { pub struct Metadata { pub info: FileMetadata, pub mermaid: bool, + pub syntax_highlight: bool, } pub fn read_md(filename: &str) -> (Metadata, String) { @@ -93,8 +94,15 @@ pub fn read_md(filename: &str) -> (Metadata, String) { .unwrap(); // Find if document contains mermaid diagram + let mermaid = Some(String::from("mermaid")); let presence_mermaid = md_nodes.iter().any(|x| match x { - markdown::mdast::Node::Code(code) => code.lang == Some(String::from("mermaid")), + markdown::mdast::Node::Code(code) => code.lang == mermaid, + _ => false, + }); + + // Find if document contains code to highlight + let presence_code = md_nodes.iter().any(|x| match x { + markdown::mdast::Node::Code(code) => code.lang != mermaid, _ => false, }); @@ -102,6 +110,7 @@ pub fn read_md(filename: &str) -> (Metadata, String) { Metadata { info: metadata, mermaid: presence_mermaid, + syntax_highlight: presence_code, }, html, )