fix some routines going only to children instead of all descendants
This commit is contained in:
parent
11e8bd3dde
commit
c200cbe07a
2 changed files with 3560 additions and 16 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue