UNPKG

course-renderer

Version:

Manages CA School Courses file system storage and HTML conversion

49 lines (39 loc) 1.24 kB
import Token from './Token' import { isSpace, isLineFeed } from './utils' import Reader from './reader' import * as handler from './handlers' //import * as handlers from './handlers' module.exports = (src: string, chapter: string) => { const tokens: Token[] = [] let pos = 0 // Initial character position. const reader = new Reader(src) const rules: any[] = [ handler.section, handler.repl, handler.question, handler.series, handler.text ] const options: handler.HandlerOptionInterface = { "sectionMode": false, "replMode" : false, "chapter": chapter } while (!reader.isEnd()) { _parse(reader, tokens, rules, options) } return tokens } function _parse(reader: Reader, tokens: Token[], rules: any[], options: handler.HandlerOptionInterface) { 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}`) } }