1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-26 15:23:15 +00:00

Improve implementation of classed runs

This commit is contained in:
Jeremy Ruston 2012-12-15 17:35:16 +00:00
parent 6ac1b7b9dc
commit 0c3c2eeec6
3 changed files with 15 additions and 17 deletions

View File

@ -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
}];
};
})();

View File

@ -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();

View File

@ -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;