From a7dd86b52af98bfaa715d09c4aaa3a2bb7772fbf Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sun, 15 Jul 2012 23:06:51 +0100 Subject: [PATCH] Adjust wikitext html rule to parse in block mode if the opening tag is immediate followed by a newline --- core/modules/parsers/newwikitextparser/rules/html.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/modules/parsers/newwikitextparser/rules/html.js b/core/modules/parsers/newwikitextparser/rules/html.js index d480269ce..306ba7cd6 100644 --- a/core/modules/parsers/newwikitextparser/rules/html.js +++ b/core/modules/parsers/newwikitextparser/rules/html.js @@ -27,10 +27,13 @@ exports.regExpString = "<[A-Za-z]+\\s*[^>]*>"; exports.parse = function(match,isBlock) { var reStart = /<([A-Za-z]+)(\s*[^>]*)>/mg, + reLineBreak = /(\r?\n)/mg, reAttr = /\s*([A-Za-z\-_]+)(?:\s*=\s*(?:("[^"]*")|('[^']*')|([^"'\s]+)))?/mg; + // Process the start regexp to get the attribute portion reStart.lastIndex = this.pos; var startMatch = reStart.exec(this.source); if(startMatch && startMatch.index === this.pos) { + // Process the attributes var attrMatch = reAttr.exec(startMatch[2]), attributes = {}; while(attrMatch) { @@ -49,6 +52,15 @@ exports.parse = function(match,isBlock) { attrMatch = reAttr.exec(startMatch[2]); } this.pos = startMatch.index + startMatch[0].length; + // Check for a line break immediate after the opening tag + reLineBreak.lastIndex = this.pos; + var lineBreakMatch = reLineBreak.exec(this.source); + if(lineBreakMatch && lineBreakMatch.index === this.pos) { + this.pos = lineBreakMatch.index + lineBreakMatch[0].length; + isBlock = true; + } else { + isBlock = false; + } var reEndString = "()", reEnd = new RegExp(reEndString,"mg"), content;