diff --git a/core/modules/parsers/wikiparser/rules/block/heading.js b/core/modules/parsers/wikiparser/rules/block/heading.js index 88098eea7..ceeb10b2c 100644 --- a/core/modules/parsers/wikiparser/rules/block/heading.js +++ b/core/modules/parsers/wikiparser/rules/block/heading.js @@ -28,16 +28,18 @@ exports.parse = function() { var headingLevel = this.match[1].length; // Move past the !s this.parser.pos = this.matchRegExp.lastIndex; - // Parse the heading - var classedRun = this.parser.parseClassedRun(/(\r?\n)/mg); + // Parse any classes, whitespace and then the heading itself + var classes = this.parser.parseClasses(); + this.parser.skipWhitespace({treatNewlinesAsNonWhitespace: true}); + var tree = this.parser.parseRun(/(\r?\n)/mg); // Return the heading return [{ type: "element", tag: "h" + this.match[1].length, attributes: { - "class": {type: "string", value: classedRun["class"]} + "class": {type: "string", value: classes.join(" ")} }, - children: classedRun.tree + children: tree }]; }; })(); diff --git a/core/modules/parsers/wikiparser/rules/block/list.js b/core/modules/parsers/wikiparser/rules/block/list.js index 9b1907918..4f2d86854 100644 --- a/core/modules/parsers/wikiparser/rules/block/list.js +++ b/core/modules/parsers/wikiparser/rules/block/list.js @@ -112,11 +112,12 @@ exports.parse = function() { // Process the body of the list item into the last list item var lastListChildren = listStack[listStack.length-1].children, lastListItem = lastListChildren[lastListChildren.length-1], - classedRun = this.parser.parseClassedRun(/(\r?\n)/mg); - lastListItem.children.push.apply(lastListItem.children,classedRun.tree); - if(classedRun["class"]) { - lastListItem.attributes = lastListItem.attributes || {}; - lastListItem.attributes["class"] = {type: "string", value: classedRun["class"]}; + classes = this.parser.parseClasses(); + this.parser.skipWhitespace({treatNewlinesAsNonWhitespace: true}); + var tree = this.parser.parseRun(/(\r?\n)/mg); + lastListItem.children.push.apply(lastListItem.children,tree); + if(classes.length > 0) { + $tw.utils.addClassToParseTreeNode(lastListItem,classes.join(" ")); } // Consume any whitespace following the list item this.parser.skipWhitespace(); diff --git a/core/modules/parsers/wikiparser/wikiparser.js b/core/modules/parsers/wikiparser/wikiparser.js index 262f73ab7..84f879655 100644 --- a/core/modules/parsers/wikiparser/wikiparser.js +++ b/core/modules/parsers/wikiparser/wikiparser.js @@ -288,9 +288,9 @@ WikiParser.prototype.parseRunTerminated = function(terminatorRegExp,options) { }; /* -Parse a run of text preceded by zero or more class specifiers `.classname` +Parse zero or more class specifiers `.classname` */ -WikiParser.prototype.parseClassedRun = function(terminatorRegExp) { +WikiParser.prototype.parseClasses = function() { var classRegExp = /\.([^\s\.]+)/mg, classNames = []; classRegExp.lastIndex = this.pos; @@ -300,12 +300,7 @@ WikiParser.prototype.parseClassedRun = function(terminatorRegExp) { classNames.push(match[1]); var match = classRegExp.exec(this.source); } - this.skipWhitespace({treatNewlinesAsNonWhitespace: true}); - var tree = this.parseRun(terminatorRegExp); - return { - "class": classNames.join(" "), - tree: tree - }; + return classNames; }; exports.WikiParser = WikiParser;