add syntax highlight
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending
ci/woodpecker/pr/publish Pipeline is pending

This commit is contained in:
Mylloon 2023-04-11 01:20:11 +02:00
parent 46ced07b2a
commit c46a61fba6
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -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,
)