fix some routines going only to children instead of all descendants

This commit is contained in:
Mylloon 2024-12-13 21:09:24 +01:00
parent 11e8bd3dde
commit c200cbe07a
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 3560 additions and 16 deletions

View file

@ -351,25 +351,22 @@ pub fn read_md(
/// Check whether mermaid diagrams are in the AST /// Check whether mermaid diagrams are in the AST
fn check_mermaid<'a>(root: &'a AstNode<'a>, mermaid_str: &str) -> bool { fn check_mermaid<'a>(root: &'a AstNode<'a>, mermaid_str: &str) -> bool {
root.children().any(|node| match &node.data.borrow().value { root.descendants()
// Check if code of block define a mermaid diagram .any(|node| match &node.data.borrow().value {
NodeValue::CodeBlock(code_block) => code_block.info == mermaid_str, // Check if code of block define a mermaid diagram
_ => false, NodeValue::CodeBlock(code_block) => code_block.info == mermaid_str,
}) _ => false,
})
} }
/// Check if code is in the AST /// Check if code is in the AST
fn check_code<'a>(root: &'a AstNode<'a>, blacklist: &[String]) -> bool { fn check_code<'a>(root: &'a AstNode<'a>, blacklist: &[String]) -> bool {
root.children().any(|node| match &node.data.borrow().value { root.descendants()
// Detect code in paragraph .any(|node| match &node.data.borrow().value {
/* NodeValue::Paragraph => match &node.children().next() { // Detect blocks of code where the lang isn't in the blacklist
Some(child) => matches!(child.data.borrow().value, NodeValue::Code(_)), NodeValue::CodeBlock(code_block) => !blacklist.contains(&code_block.info),
None => false, _ => false,
}, */ })
// Detect blocks of code where the lang isn't in the blacklist
NodeValue::CodeBlock(code_block) => !blacklist.contains(&code_block.info),
_ => false,
})
} }
/// Check if html contains maths /// Check if html contains maths
@ -394,7 +391,7 @@ fn check_math(html: &str) -> bool {
/// Change class of languages for hljs detection /// Change class of languages for hljs detection
fn hljs_replace<'a>(root: &'a AstNode<'a>, mermaid_str: &str) { fn hljs_replace<'a>(root: &'a AstNode<'a>, mermaid_str: &str) {
root.children().for_each(|node| { root.descendants().for_each(|node| {
if let NodeValue::CodeBlock(ref mut block) = &mut node.data.borrow_mut().value { if let NodeValue::CodeBlock(ref mut block) = &mut node.data.borrow_mut().value {
if block.info != mermaid_str { if block.info != mermaid_str {
block.info = format!("hljs-{}", block.info); block.info = format!("hljs-{}", block.info);

3547
tmp.log Normal file

File diff suppressed because it is too large Load diff