chore: format curriculum (#37912)
This commit is contained in:
committed by
GitHub
parent
45fe3d8814
commit
22fbc62f88
30
tools/scripts/formatter/md-to-mdx/plugins/text-to-data.js
Normal file
30
tools/scripts/formatter/md-to-mdx/plugins/text-to-data.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const stringify = require('remark-stringify');
|
||||
const { root } = require('mdast-builder');
|
||||
const unified = require('unified');
|
||||
const getAllBetween = require('../utils/get-all-between');
|
||||
|
||||
const stringifyMd = nodes =>
|
||||
unified()
|
||||
.use(stringify, { fences: true, emphasis: '*' })
|
||||
.stringify(root(nodes));
|
||||
|
||||
function plugin() {
|
||||
return transformer;
|
||||
|
||||
function transformer(tree, file) {
|
||||
const descriptionNodes = getAllBetween(
|
||||
tree,
|
||||
{ type: 'html', value: "<section id='description'>" },
|
||||
{ type: 'html', value: '</section>' }
|
||||
);
|
||||
file.data.description = stringifyMd(descriptionNodes);
|
||||
const instructionsNodes = getAllBetween(
|
||||
tree,
|
||||
{ type: 'html', value: "<section id='instructions'>" },
|
||||
{ type: 'html', value: '</section>' }
|
||||
);
|
||||
file.data.instructions = stringifyMd(instructionsNodes);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = plugin;
|
Reference in New Issue
Block a user