mirror of
https://github.com/benjaminion/upgrading-ethereum-book.git
synced 2026-01-09 14:38:08 -05:00
Walk the tree only once
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
import { visit, SKIP } from 'unist-util-visit';
|
||||
import { visit, CONTINUE, SKIP } from 'unist-util-visit';
|
||||
|
||||
// Clean up any weird HTML artefacts, especially those that fail validation
|
||||
|
||||
function cleanupHtml() {
|
||||
return function (tree) {
|
||||
// Remove `is:raw=""` that's on `code` elements, probably from Prism.
|
||||
visit(tree, 'element', (node) => {
|
||||
if (node.tagName == 'code') {
|
||||
visit(tree, undefined, (node, index, parent) => {
|
||||
// Remove `is:raw=""` that's on `code` elements, probably from Prism
|
||||
if (node.type === 'element' && node.tagName === 'code') {
|
||||
delete node.properties['is:raw'];
|
||||
return CONTINUE;
|
||||
}
|
||||
// Remove all comments
|
||||
if (node.type === 'comment') {
|
||||
parent.children.splice(index, 1);
|
||||
return SKIP;
|
||||
}
|
||||
});
|
||||
|
||||
// Remove any comments
|
||||
visit(tree, 'comment', (node, index, parent) => {
|
||||
parent.children.splice(index, 1);
|
||||
return SKIP;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user