course-renderer
Version:
Manages CA School Courses file system storage and HTML conversion
86 lines (85 loc) • 3.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const Token_1 = require("../Token");
const rules = require("../rules");
const handlers_1 = require("../handlers");
const SERIES_MARKER = 0x3A; /* : */
function series(reader, tokens, silent = false, options) {
let pos = reader.getCurrentLineStartPos();
if (reader.getCharCode(pos++) !== SERIES_MARKER
|| reader.getCharCode(pos++) !== SERIES_MARKER
|| reader.getCharCode(pos++) !== SERIES_MARKER) {
return false;
}
if (silent)
return true;
if (options.replMode) {
options.replMode = false;
reader.nextNonEmptyLines();
}
else {
reader.nextNonEmptyLines();
let token;
if (!rules.annotation(reader, true)) {
handlers_1.text(reader, tokens, false, options);
// We will then need to override the type of token that the text handler created since it should be an REPL token
// check if we're inside a section token
if (options.sectionMode) {
const sectionTokChildren = tokens[tokens.length - 1].children;
token = sectionTokChildren[sectionTokChildren.length - 1];
token.setType('REPL');
}
else {
token = tokens[tokens.length - 1];
token.setType('REPL');
token.children = [];
}
}
else {
token = new Token_1.default('REPL');
token.setChapter(options.chapter);
if (options.sectionMode) {
const sectionTok = tokens[tokens.length - 1];
token.children = [];
sectionTok.addChild(token);
}
else {
tokens.push(token);
}
}
if (!rules.annotation(reader, true))
throw new Error(`Expecting an annotation at line ${reader.currentLine}`);
const annotation = rules.annotation(reader, false);
token.setReadonly(annotation.readonly === 'true' ? true : false);
if (annotation.caption && annotation.caption.length > 0) {
token.setCaption(annotation.caption);
}
if (annotation.init != null) {
token.setInitialization(annotation.init);
}
if (annotation.type !== 'REPL')
throw new Error(`Expecting an REPL annotation at line ${reader.currentLine}`);
if (annotation.files != null) {
const files = annotation.files.split(/,\s*/);
files.forEach((file) => {
token.addFile(file);
});
}
reader.skipEmptyLines();
if (!rules.fence(reader, tokens, true, options))
throw new Error(`REPL type expects a fence markup at line ${reader.currentLine}`);
rules.fence(reader, tokens, false, options);
// Let us check if there is another fence block after this.
while (true) {
reader.nextNonEmptyLines();
if (rules.fence(reader, tokens, true, options)) {
rules.fence(reader, tokens, false, options);
continue;
}
break;
}
options.replMode = true;
}
return true;
}
exports.series = series;