From 52f86e7b0122696c2d91e816213970ae350a298a Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 7 Jun 2012 13:08:50 +0100 Subject: [PATCH] Added parseBlockTerminated() method to new wikitext parser --- .../newwikitextparser/newwikitextparser.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/core/modules/parsers/newwikitextparser/newwikitextparser.js b/core/modules/parsers/newwikitextparser/newwikitextparser.js index 74ad1aa45..a9fa9931d 100644 --- a/core/modules/parsers/newwikitextparser/newwikitextparser.js +++ b/core/modules/parsers/newwikitextparser/newwikitextparser.js @@ -65,6 +65,39 @@ WikiTextRenderer.prototype.parseBlock = function() { } }; +/* +Parse blocks of text until a terminating regexp is encountered + terminatorRegExp: terminating regular expression + addClass: optional CSS class to add to each block +*/ +WikiTextRenderer.prototype.parseBlockTerminated = function(terminatorRegExp,className) { + var tree = []; + // Skip any whitespace + this.skipWhitespace(); + // Check if we've got the end marker + terminatorRegExp.lastIndex = this.pos; + var match = terminatorRegExp.exec(this.source); + // Parse the text into blocks + while(this.pos < this.sourceLength && !(match && match.index === this.pos)) { + var blocks = this.parseBlock(); + for(var t=0; t