UNPKG

course-renderer

Version:

Manages CA School Courses file system storage and HTML conversion

28 lines (27 loc) 962 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const MarkdownIt = require("markdown-it"); function transform(tokens, includeList) { const md = new MarkdownIt({ html: true }); if (!includeList) { md.disable(['list']); } render(tokens, md); return tokens; } exports.transform = transform; function render(tokens, md) { tokens.forEach((token) => { if (token.children instanceof Array) { render(token.children, md); } if (token.content && token.content.length > 0) { token.content = md.render(token.content).replace(/\n$/, ''); // Remove trailing new line added by markdown-it } if (token.type === 'SS' || token.type === 'MS') { token.choices.forEach((val, index) => { token.choices[index] = md.render(val).replace(/\n$/, ''); // Remove trailing new line added by markdown-it }); } }); }