UNPKG

course-renderer

Version:

Manages CA School Courses file system storage and HTML conversion

77 lines (55 loc) 2.33 kB
import Token from '../Token' import Reader from '../reader' import * as rules from '../rules' import { AnnotationInterface } from '../rules/annotation' import { text, question, HandlerOptionInterface } from '../handlers' export function repl(reader: Reader, tokens: Token[], silent: boolean = false, options: HandlerOptionInterface): boolean { if (!rules.annotation(reader, true)) return false const parsedAnnotation = rules.annotation(reader, false) if (parsedAnnotation.type !== 'REPL') { reader.currentLine-- // Revert the reader line pointer since this handler will not handle it. return false } if (silent) return true reader.nextNonEmptyLines() if (!rules.fence(reader, tokens, true, options)) throw new Error(`REPL type expects a fence markup at line ${reader.currentLine + 1}`) const token = new Token(parsedAnnotation.type) token.setChapter(options.chapter) token.setReadonly(parsedAnnotation.readonly === 'true' ? true : false) if (parsedAnnotation.caption && parsedAnnotation.caption.length > 0) { token.setCaption(parsedAnnotation.caption) } if (parsedAnnotation.init != null) { token.setInitialization(parsedAnnotation.init) } if (parsedAnnotation.files != null) { const files = parsedAnnotation.files.split(/,\s*/); files.forEach((file: string) => { token.addFile(file) }); } if (options.sectionMode && options.replMode) { const sectionTokChildren = tokens[tokens.length - 1].children const replTok = sectionTokChildren[sectionTokChildren.length - 1] replTok.addChild(token) } else if (options.sectionMode || options.replMode) { tokens[tokens.length - 1].addChild(token) } else { tokens.push(token) } 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 //reader.nextNonEmptyLines() question(reader, tokens, false, options) options.replMode = false return true }