chore: remove old parser
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
e3511f2930
commit
a3a678b7af
35
tools/challenge-parser/parser/plugins/add-ids.js
Normal file
35
tools/challenge-parser/parser/plugins/add-ids.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const visitChildren = require('unist-util-visit-children');
|
||||
|
||||
function hasId(node, index, parent) {
|
||||
// image references should always be inside paragraphs.
|
||||
if (node.type !== 'paragraph') return;
|
||||
const idHolder = node.children[0];
|
||||
if (idHolder.type === 'imageReference') {
|
||||
if (node.children.length > 1) {
|
||||
console.log('oooops, too many links together!');
|
||||
// TODO: optional chaining
|
||||
} else if (
|
||||
parent.children[index + 1] &&
|
||||
parent.children[index + 1].type === 'code'
|
||||
) {
|
||||
console.log('found adjacent code block for id ' + idHolder.identifier);
|
||||
} else {
|
||||
console.log(
|
||||
'ooops! the id ' + idHolder.identifier + ' is not next to a code block'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function plugin() {
|
||||
// we don't want to recurse into the tree, hence visitChildren
|
||||
|
||||
const visit = visitChildren(hasId);
|
||||
return transformer;
|
||||
|
||||
function transformer(tree) {
|
||||
visit(tree);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = plugin;
|
Reference in New Issue
Block a user