fix: parse ::directives correctly (#41186)
This commit is contained in:
committed by
GitHub
parent
b12360d4a8
commit
04c2f4e620
32
tools/challenge-parser/parser/plugins/restore-directives.js
Normal file
32
tools/challenge-parser/parser/plugins/restore-directives.js
Normal file
@ -0,0 +1,32 @@
|
||||
const visit = require('unist-util-visit');
|
||||
const { matches } = require('unist-util-select');
|
||||
const directive = require('mdast-util-directive');
|
||||
var toMarkdown = require('mdast-util-to-markdown');
|
||||
|
||||
function plugin() {
|
||||
return transformer;
|
||||
|
||||
function transformer(tree) {
|
||||
visit(tree, visitor);
|
||||
|
||||
function visitor(node, id, parent) {
|
||||
// currently `remark-directive` seems to be ignoring containerDirectives
|
||||
// but, assuming that will get fixed, we test for it anyway.
|
||||
const isDirective =
|
||||
matches('leafDirective', node) ||
|
||||
matches('textDirective', node) ||
|
||||
matches('containerDirective', node);
|
||||
|
||||
if (isDirective) {
|
||||
parent.children[id] = {
|
||||
type: 'text',
|
||||
value: toMarkdown(node, {
|
||||
extensions: [directive.toMarkdown]
|
||||
}).trim()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = plugin;
|
Reference in New Issue
Block a user