* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
33 lines
1.0 KiB
JavaScript
33 lines
1.0 KiB
JavaScript
const chunk = require('lodash/chunk');
|
|
const getAllBetween = require('../../../challenge-md-parser/mdx/plugins/utils/between-headings');
|
|
const { stringifyMd } = require('./text-to-data');
|
|
|
|
function plugin() {
|
|
return transformer;
|
|
|
|
function transformer(tree, file) {
|
|
const hintNodes = getAllBetween(tree, '--hints--');
|
|
if (hintNodes.length % 2 !== 0)
|
|
throw Error('Tests must be in (text, ```testString```) order');
|
|
|
|
const tests = chunk(hintNodes, 2).map(getTest);
|
|
file.data.tests = tests;
|
|
}
|
|
}
|
|
|
|
function getTest(hintNodes) {
|
|
const [textNode, testStringNode] = hintNodes;
|
|
const text = stringifyMd([textNode]);
|
|
const testString = stringifyMd([testStringNode]);
|
|
|
|
if (!text) throw Error('text is missing from hint');
|
|
// stub tests (i.e. text, but no testString) are allowed, but the md must
|
|
// have a code block, even if it is empty.
|
|
if (!testString && testString !== '')
|
|
throw Error('testString (code block) is missing from hint');
|
|
|
|
return { text, testString };
|
|
}
|
|
|
|
module.exports = plugin;
|