UNPKG

course-renderer

Version:

Manages CA School Courses file system storage and HTML conversion

40 lines (39 loc) 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const reader_1 = require("./reader"); const handler = require("./handlers"); //import * as handlers from './handlers' module.exports = (src, chapter) => { const tokens = []; let pos = 0; // Initial character position. const reader = new reader_1.default(src); const rules = [ handler.section, handler.repl, handler.question, handler.series, handler.text ]; const options = { "sectionMode": false, "replMode": false, "chapter": chapter }; while (!reader.isEnd()) { _parse(reader, tokens, rules, options); } return tokens; }; function _parse(reader, tokens, rules, options) { let handled = false; for (let index = 0; index < rules.length; index++) { const handler = rules[index]; if (handler(reader, tokens, false, options)) { handled = true; break; } } if (!handled) { console.error(`Unable to handle the current line ${reader.currentLine} of chapter ${options.chapter}`); } }