mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 20:10:03 +00:00
Enhanced wiki text parser to selectively eat terminator regexp matches
This commit is contained in:
parent
7593cf1075
commit
228ee92e95
@ -204,16 +204,19 @@ WikiParser.prototype.parseBlocksTerminated = function(terminatorRegExpString) {
|
|||||||
/*
|
/*
|
||||||
Parse a run of text at the current position
|
Parse a run of text at the current position
|
||||||
terminatorRegExp: a regexp at which to stop the run
|
terminatorRegExp: a regexp at which to stop the run
|
||||||
|
options: see below
|
||||||
|
Options available:
|
||||||
|
eatTerminator: move the parse position past any encountered terminator (default false)
|
||||||
*/
|
*/
|
||||||
WikiParser.prototype.parseRun = function(terminatorRegExp) {
|
WikiParser.prototype.parseRun = function(terminatorRegExp,options) {
|
||||||
if(terminatorRegExp) {
|
if(terminatorRegExp) {
|
||||||
return this.parseRunTerminated(terminatorRegExp);
|
return this.parseRunTerminated(terminatorRegExp,options);
|
||||||
} else {
|
} else {
|
||||||
return this.parseRunUnterminated();
|
return this.parseRunUnterminated(options);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
WikiParser.prototype.parseRunUnterminated = function() {
|
WikiParser.prototype.parseRunUnterminated = function(options) {
|
||||||
var tree = [];
|
var tree = [];
|
||||||
// Find the next occurrence of a runrule
|
// Find the next occurrence of a runrule
|
||||||
var nextMatch = this.findNextMatch(this.runRules,this.pos);
|
var nextMatch = this.findNextMatch(this.runRules,this.pos);
|
||||||
@ -237,7 +240,8 @@ WikiParser.prototype.parseRunUnterminated = function() {
|
|||||||
return tree;
|
return tree;
|
||||||
};
|
};
|
||||||
|
|
||||||
WikiParser.prototype.parseRunTerminated = function(terminatorRegExp) {
|
WikiParser.prototype.parseRunTerminated = function(terminatorRegExp,options) {
|
||||||
|
options = options || {};
|
||||||
var tree = [];
|
var tree = [];
|
||||||
// Find the next occurrence of the terminator
|
// Find the next occurrence of the terminator
|
||||||
terminatorRegExp.lastIndex = this.pos;
|
terminatorRegExp.lastIndex = this.pos;
|
||||||
@ -253,6 +257,9 @@ WikiParser.prototype.parseRunTerminated = function(terminatorRegExp) {
|
|||||||
tree.push({type: "text", text: this.source.substring(this.pos,terminatorMatch.index)});
|
tree.push({type: "text", text: this.source.substring(this.pos,terminatorMatch.index)});
|
||||||
}
|
}
|
||||||
this.pos = terminatorMatch.index;
|
this.pos = terminatorMatch.index;
|
||||||
|
if(options.eatTerminator) {
|
||||||
|
this.pos += terminatorMatch[0].length;
|
||||||
|
}
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user