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

3547
tmp.log Normal file

File diff suppressed because it is too large Load diff