course-renderer
Version:
Manages CA School Courses file system storage and HTML conversion
30 lines (29 loc) • 1.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const MarkdownIt = require("markdown-it");
const replaceExtension = require('replace-ext');
const through = require('through2');
const parser = require('../markdown/parser');
module.exports = (options) => (through.obj((file, _, callback) => {
if (file.isNull()) {
callback(null, file);
return;
}
if (file.isStream()) {
callback(new Error('Streaming not supported'));
return;
}
const md = new MarkdownIt();
const filePath = replaceExtension(file.path, '.json');
try {
const tokens = parser(file.contents.toString(), filePath.replace(options.sourcePath + path.sep, ''));
file.contents = new Buffer(JSON.stringify(tokens, null, 4));
}
catch (e) {
callback(new Error(`${file.path.replace(options.sourcePath + path.sep, '')}: ${e.message}`));
return;
}
file.path = filePath;
callback(null, file);
}));