feat: process video question md into html (#38667)

* feat: process video question md into html

* test: mdToHTML

* fix: use dedicated prism component
This commit is contained in:
Oliver Eyton-Williams
2020-05-05 14:50:30 +02:00
committed by Mrugesh Mohapatra
parent 04412cbf6f
commit de0bec88a3
11 changed files with 346 additions and 110 deletions

View File

@ -1,5 +1,20 @@
const visit = require('unist-util-visit');
const YAML = require('js-yaml');
const unified = require('unified');
const markdown = require('remark-parse');
const remark2rehype = require('remark-rehype');
const html = require('rehype-stringify');
const raw = require('rehype-raw');
const processor = unified()
.use(markdown)
.use(remark2rehype, { allowDangerousHTML: true })
.use(raw)
.use(html);
function mdToHTML(str) {
return processor.processSync(str).toString();
}
function plugin() {
return transformer;
@ -11,6 +26,12 @@ function plugin() {
const { lang, value } = node;
if (lang === 'yml') {
const tests = YAML.load(value);
if (tests.question) {
tests.question.answers = tests.question.answers.map(answer =>
mdToHTML(answer)
);
tests.question.text = mdToHTML(tests.question.text);
}
file.data = {
...file.data,
...tests
@ -21,3 +42,4 @@ function plugin() {
}
module.exports = plugin;
module.exports.mdToHTML = mdToHTML;