course-renderer
Version:
Manages CA School Courses file system storage and HTML conversion
48 lines (47 loc) • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../utils");
function option(reader, tokens, silent = false, options) {
if (!hasMarker(reader))
return false;
if (silent)
return true;
const start = reader.currentLine;
const initialPos = reader.getCurrentLineStartPos();
const endPos = skipMarker(reader);
const endLine = reader.jumpBeforeEmptyLines();
let optionLines = reader.getLines(start, endLine);
optionLines = optionLines.substring(endPos - initialPos);
const token = tokens[tokens.length - 1];
if (options.sectionMode && options.replMode) {
const replToken = token.children[token.children.length - 1];
const lastToken = replToken.children[replToken.children.length - 1];
lastToken.addChoice(optionLines);
}
else if (options.sectionMode || options.replMode) {
const childToken = token.children[token.children.length - 1];
childToken.addChoice(optionLines);
}
else {
token.addChoice(optionLines);
}
reader.currentLine = endLine;
}
exports.option = option;
function hasMarker(reader) {
let pos = reader.skipEmptyChars();
let max = reader.getCurrentLineEndPos();
if (reader.getCharCode(pos++) !== 0x2D /* - */)
return false;
if (!utils_1.isSpace(reader.getCharCode(pos++)))
return false;
pos = reader.skipSpaces(pos);
if (pos === max)
return false;
return true;
}
function skipMarker(reader) {
let pos = reader.skipEmptyChars() + 1;
pos = reader.skipSpaces(pos);
return pos;
}