feat: markdown implementation #18

Merged
Anri merged 9 commits from feat/md into main 2023-04-11 01:25:45 +02:00
Showing only changes of commit c46a61fba6 - Show all commits

View file

@ -51,6 +51,7 @@ pub struct FileMetadata {
pub struct Metadata { pub struct Metadata {
pub info: FileMetadata, pub info: FileMetadata,
pub mermaid: bool, pub mermaid: bool,
pub syntax_highlight: bool,
} }
pub fn read_md(filename: &str) -> (Metadata, String) { pub fn read_md(filename: &str) -> (Metadata, String) {
@ -93,8 +94,15 @@ pub fn read_md(filename: &str) -> (Metadata, String) {
.unwrap(); .unwrap();
// Find if document contains mermaid diagram // Find if document contains mermaid diagram
let mermaid = Some(String::from("mermaid"));
let presence_mermaid = md_nodes.iter().any(|x| match x { 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, _ => false,
}); });
@ -102,6 +110,7 @@ pub fn read_md(filename: &str) -> (Metadata, String) {
Metadata { Metadata {
info: metadata, info: metadata,
mermaid: presence_mermaid, mermaid: presence_mermaid,
syntax_highlight: presence_code,
}, },
html, html,
) )