mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-07 22:33:50 +00:00
Refactored run parser so that it can optionally not consume the terminator
This commit is contained in:
parent
2c5913116b
commit
f50e025f7c
@ -77,17 +77,22 @@ WikiTextRenderer.prototype.skipWhitespace = function() {
|
|||||||
/*
|
/*
|
||||||
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 are:
|
||||||
|
leaveTerminator: true if the terminator shouldn't be consumed
|
||||||
Returns an array of tree nodes
|
Returns an array of tree nodes
|
||||||
*/
|
*/
|
||||||
WikiTextRenderer.prototype.parseRun = function(terminatorRegExp) {
|
WikiTextRenderer.prototype.parseRun = function(terminatorRegExp,options) {
|
||||||
if(terminatorRegExp === null) {
|
if(terminatorRegExp === null) {
|
||||||
return this.parseRunUnterminated();
|
return this.parseRunUnterminated(options);
|
||||||
} else {
|
} else {
|
||||||
return this.parseRunTerminated(terminatorRegExp);
|
return this.parseRunTerminated(terminatorRegExp,options);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
WikiTextRenderer.prototype.parseRunUnterminated = function() {
|
WikiTextRenderer.prototype.parseRunUnterminated = function(options) {
|
||||||
|
options = options || {};
|
||||||
var tree = [];
|
var tree = [];
|
||||||
// Find the next occurrence of a runrule
|
// Find the next occurrence of a runrule
|
||||||
this.parser.runRegExp.lastIndex = this.pos;
|
this.parser.runRegExp.lastIndex = this.pos;
|
||||||
@ -121,7 +126,8 @@ WikiTextRenderer.prototype.parseRunUnterminated = function() {
|
|||||||
return tree;
|
return tree;
|
||||||
};
|
};
|
||||||
|
|
||||||
WikiTextRenderer.prototype.parseRunTerminated = function(terminatorRegExp) {
|
WikiTextRenderer.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 = terminatorRegExp || /(\r?\n\r?\n)/mg;
|
terminatorRegExp = terminatorRegExp || /(\r?\n\r?\n)/mg;
|
||||||
@ -138,7 +144,10 @@ WikiTextRenderer.prototype.parseRunTerminated = function(terminatorRegExp) {
|
|||||||
if(terminatorMatch.index > this.pos) {
|
if(terminatorMatch.index > this.pos) {
|
||||||
tree.push($tw.Tree.Text(this.source.substring(this.pos,terminatorMatch.index)));
|
tree.push($tw.Tree.Text(this.source.substring(this.pos,terminatorMatch.index)));
|
||||||
}
|
}
|
||||||
this.pos = terminatorMatch.index + terminatorMatch[0].length;
|
this.pos = terminatorMatch.index;
|
||||||
|
if(!options.leaveTerminator) {
|
||||||
|
this.pos += terminatorMatch[0].length;
|
||||||
|
}
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user