test02/node_modules/@vuepress/plugin-prismjs/lib/node/parser/createNotationRule.js
罗佳鸿 6aa1ebe342
Some checks are pending
部署文档 / deploy-gh-pages (push) Waiting to run
first commit
2024-08-13 10:11:19 +08:00

22 lines
741 B
JavaScript

// prismjs comments
const COMMENT_EMPTY_TAG = /<span class="token comment">\s*?<\/span>/;
export const createNotationRule = (parser, pattern, onMatch) => {
const nodeRemove = [];
parser.lines.forEach((node, index) => {
let replaced = false;
node.content = node.content.replace(pattern, (...match) => {
if (onMatch(match, index)) {
replaced = true;
return '';
}
return match[0];
});
if (replaced &&
!(node.content = node.content.replace(COMMENT_EMPTY_TAG, '')).trim()) {
nodeRemove.push(node);
}
});
for (const node of nodeRemove)
parser.lines.splice(parser.lines.indexOf(node), 1);
};