Oliver Eyton-Williams eb8359c281
feat: add script to annotate challenges for translation (#40366)
* feat: add script to annotate challenges for translation

* fix: readdirp-walk -> readdirp

* fix: remove notranslate for frontmatter

* fix: don't output seed/solution

* feat: convert to function

Also puts in some missing 'async's to make it clearer what returns
promises.

* refactor: use meaningful names

* refactor: remove comments

* chore: update dependencies

* chore: move dir

* fix(crowdin): annotate individual answers
2020-12-23 12:04:56 -07:00

27 lines
849 B
JavaScript

const stringify = require('remark-stringify');
const { root } = require('mdast-builder');
const unified = require('unified');
const getAllBetween = require('../../../challenge-md-parser/mdx/plugins/utils/between-headings');
const stringifyMd = nodes =>
unified()
.use(stringify, { fences: true, emphasis: '*' })
.stringify(root(nodes));
// NOTE: we need a new plugin (rather than using the challenge parser's plugin)
// simply because it adds html to the descriptions. It's easier to start from
// scratch.
function plugin() {
return transformer;
function transformer(tree, file) {
file.data.description = stringifyMd(getAllBetween(tree, '--description--'));
file.data.instructions = stringifyMd(
getAllBetween(tree, '--instructions--')
);
}
}
module.exports = plugin;
module.exports.stringifyMd = stringifyMd;