Feat: add new Markdown parser (#39800)
and change all the challenges to new `md` format.
This commit is contained in:
committed by
GitHub
parent
a07f84c8ec
commit
0bd52f8bd1
27
tools/challenge-md-parser/mdx/plugins/add-text.js
Normal file
27
tools/challenge-md-parser/mdx/plugins/add-text.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const { isEmpty } = require('lodash');
|
||||
const getAllBetween = require('./utils/between-headings');
|
||||
const mdastToHTML = require('./utils/mdast-to-html');
|
||||
|
||||
function addText(sectionIds) {
|
||||
if (!sectionIds || !Array.isArray(sectionIds) || sectionIds.length <= 0) {
|
||||
throw new Error('addText must have an array of section ids supplied');
|
||||
}
|
||||
function transformer(tree, file) {
|
||||
for (const sectionId of sectionIds) {
|
||||
const textNodes = getAllBetween(tree, `--${sectionId}--`);
|
||||
const sectionText = mdastToHTML(textNodes);
|
||||
|
||||
if (!isEmpty(sectionText)) {
|
||||
file.data = {
|
||||
...file.data,
|
||||
[sectionId]: `<section id="${sectionId}">
|
||||
${sectionText}
|
||||
</section>`
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
return transformer;
|
||||
}
|
||||
|
||||
module.exports = addText;
|
Reference in New Issue
Block a user