kopia lustrzana https://github.com/miklobit/TiddlyWiki5
Improve implementation of classed runs
rodzic
6ac1b7b9dc
commit
0c3c2eeec6
|
@ -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
|
||||
}];
|
||||
};
|
||||
})();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Ładowanie…
Reference in New Issue