Improve implementation of classed runs

print-window-tiddler
Jeremy Ruston 2012-12-15 17:35:16 +00:00
rodzic 6ac1b7b9dc
commit 0c3c2eeec6
3 zmienionych plików z 15 dodań i 17 usunięć

Wyświetl plik

@ -28,16 +28,18 @@ exports.parse = function() {
var headingLevel = this.match[1].length; var headingLevel = this.match[1].length;
// Move past the !s // Move past the !s
this.parser.pos = this.matchRegExp.lastIndex; this.parser.pos = this.matchRegExp.lastIndex;
// Parse the heading // Parse any classes, whitespace and then the heading itself
var classedRun = this.parser.parseClassedRun(/(\r?\n)/mg); var classes = this.parser.parseClasses();
this.parser.skipWhitespace({treatNewlinesAsNonWhitespace: true});
var tree = this.parser.parseRun(/(\r?\n)/mg);
// Return the heading // Return the heading
return [{ return [{
type: "element", type: "element",
tag: "h" + this.match[1].length, tag: "h" + this.match[1].length,
attributes: { attributes: {
"class": {type: "string", value: classedRun["class"]} "class": {type: "string", value: classes.join(" ")}
}, },
children: classedRun.tree children: tree
}]; }];
}; };
})(); })();

Wyświetl plik

@ -112,11 +112,12 @@ exports.parse = function() {
// Process the body of the list item into the last list item // Process the body of the list item into the last list item
var lastListChildren = listStack[listStack.length-1].children, var lastListChildren = listStack[listStack.length-1].children,
lastListItem = lastListChildren[lastListChildren.length-1], lastListItem = lastListChildren[lastListChildren.length-1],
classedRun = this.parser.parseClassedRun(/(\r?\n)/mg); classes = this.parser.parseClasses();
lastListItem.children.push.apply(lastListItem.children,classedRun.tree); this.parser.skipWhitespace({treatNewlinesAsNonWhitespace: true});
if(classedRun["class"]) { var tree = this.parser.parseRun(/(\r?\n)/mg);
lastListItem.attributes = lastListItem.attributes || {}; lastListItem.children.push.apply(lastListItem.children,tree);
lastListItem.attributes["class"] = {type: "string", value: classedRun["class"]}; if(classes.length > 0) {
$tw.utils.addClassToParseTreeNode(lastListItem,classes.join(" "));
} }
// Consume any whitespace following the list item // Consume any whitespace following the list item
this.parser.skipWhitespace(); this.parser.skipWhitespace();

Wyświetl plik

@ -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, var classRegExp = /\.([^\s\.]+)/mg,
classNames = []; classNames = [];
classRegExp.lastIndex = this.pos; classRegExp.lastIndex = this.pos;
@ -300,12 +300,7 @@ WikiParser.prototype.parseClassedRun = function(terminatorRegExp) {
classNames.push(match[1]); classNames.push(match[1]);
var match = classRegExp.exec(this.source); var match = classRegExp.exec(this.source);
} }
this.skipWhitespace({treatNewlinesAsNonWhitespace: true}); return classNames;
var tree = this.parseRun(terminatorRegExp);
return {
"class": classNames.join(" "),
tree: tree
};
}; };
exports.WikiParser = WikiParser; exports.WikiParser = WikiParser;