This commit is contained in:
parent
0541887c28
commit
69149681f7
1 changed files with 17 additions and 31 deletions
|
@ -75,12 +75,13 @@ pub fn read(raw_text: &str) -> File {
|
||||||
let mut html = vec![];
|
let mut html = vec![];
|
||||||
format_html(root, &options, &mut html).unwrap();
|
format_html(root, &options, &mut html).unwrap();
|
||||||
|
|
||||||
|
let mermaid_name = "mermaid";
|
||||||
|
|
||||||
File {
|
File {
|
||||||
metadata: Metadata {
|
metadata: Metadata {
|
||||||
info: metadata,
|
info: metadata,
|
||||||
math: false,
|
mermaid: check_mermaid(root, mermaid_name.to_string()),
|
||||||
mermaid: false,
|
syntax_highlight: check_code(root, &[mermaid_name.to_string()]),
|
||||||
syntax_highlight: false,
|
|
||||||
},
|
},
|
||||||
content: String::from_utf8(html).unwrap(),
|
content: String::from_utf8(html).unwrap(),
|
||||||
}
|
}
|
||||||
|
@ -110,40 +111,25 @@ pub fn get_metadata<'a>(root: &'a AstNode<'a>) -> FileMetadata {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* /// Check recursively if maths is in the AST
|
|
||||||
fn check_math(vec: &[Node]) -> bool {
|
|
||||||
vec.iter().any(|x| {
|
|
||||||
matches!(x, Node::Math(_) | Node::InlineMath(_))
|
|
||||||
|| match x.children() {
|
|
||||||
Some(children) => check_math(children),
|
|
||||||
None => false,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Recursively check whether mermaid diagrams are in the AST
|
/// Recursively check whether mermaid diagrams are in the AST
|
||||||
fn check_mermaid(vec: &[Node], mermaid_str: String) -> bool {
|
fn check_mermaid<'a>(root: &'a AstNode<'a>, mermaid_str: String) -> bool {
|
||||||
vec.iter().any(|x| match x {
|
root.children().any(|node| match &node.data.borrow().value {
|
||||||
Node::Code(code) => code.lang == Some(mermaid_str.clone()),
|
// Check if code of block define a mermaid diagram
|
||||||
|
NodeValue::CodeBlock(code_block) => code_block.info == mermaid_str,
|
||||||
_ => false,
|
_ => false,
|
||||||
} || match x.children() {
|
|
||||||
Some(children) => check_mermaid(children, mermaid_str.clone()),
|
|
||||||
None => false
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recursively check if code is in the AST
|
/// Recursively check if code is in the AST
|
||||||
fn check_code(vec: &[Node], blacklist: Vec<String>) -> bool {
|
fn check_code<'a>(root: &'a AstNode<'a>, blacklist: &[String]) -> bool {
|
||||||
vec.iter().any(|x| match x {
|
root.children().any(|node| match &node.data.borrow().value {
|
||||||
Node::InlineCode(_) => true,
|
// Detect code in paragraph
|
||||||
Node::Code(code) => match &code.lang {
|
/* NodeValue::Paragraph => match &node.children().next() {
|
||||||
Some(lang) => !blacklist.contains(lang),
|
Some(child) => matches!(child.data.borrow().value, NodeValue::Code(_)),
|
||||||
None => true,
|
None => false,
|
||||||
},
|
}, */
|
||||||
|
// Detect blocks of code where the lang isn't in the blacklist
|
||||||
|
NodeValue::CodeBlock(code_block) => !blacklist.contains(&code_block.info),
|
||||||
_ => false,
|
_ => false,
|
||||||
} || match x.children() {
|
|
||||||
Some(children) => check_code(children, blacklist.clone()),
|
|
||||||
None => false
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
Loading…
Reference in a new issue