diff --git a/core/modules/parsers/newwikitextparser/newwikitextparser.js b/core/modules/parsers/newwikitextparser/newwikitextparser.js index 8517ed227..6397f607f 100644 --- a/core/modules/parsers/newwikitextparser/newwikitextparser.js +++ b/core/modules/parsers/newwikitextparser/newwikitextparser.js @@ -23,9 +23,13 @@ var WikiTextRenderer = function(text,options) { this.parser = options.parser; this.tree = []; this.dependencies = new $tw.Dependencies(); - // Parse the text into blocks - while(this.pos < this.sourceLength) { - this.tree.push.apply(this.tree,this.parseBlock()); + if(options.isRun) { + this.tree.push.apply(this.tree,this.parseRun(null)); + } else { + // Parse the text into blocks + while(this.pos < this.sourceLength) { + this.tree.push.apply(this.tree,this.parseBlock()); + } } }; @@ -76,6 +80,48 @@ Parse a run of text at the current position Returns an array of tree nodes */ WikiTextRenderer.prototype.parseRun = function(terminatorRegExp) { + if(terminatorRegExp === null) { + return this.parseRunUnterminated(); + } else { + return this.parseRunTerminated(terminatorRegExp); + } +}; + +WikiTextRenderer.prototype.parseRunUnterminated = function() { + var tree = []; + // Find the next occurrence of a runrule + this.parser.runRegExp.lastIndex = this.pos; + var runRuleMatch = this.parser.runRegExp.exec(this.source); + // Loop around until we've reached the end of the text + while(this.pos < this.sourceLength && runRuleMatch) { + // Process the text preceding the run rule + if(runRuleMatch.index > this.pos) { + tree.push($tw.Tree.Text(this.source.substring(this.pos,runRuleMatch.index))); + this.pos = runRuleMatch.index; + } + // Process the run rule + var rule; + for(var t=0; t