mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-03-12 22:48:09 +00:00
Removed fallback range logic
This commit is contained in:
parent
62fdaa633a
commit
9b247f6d63
@ -185,36 +185,6 @@ WikiParser.prototype.findNextMatch = function(rules,startPos) {
|
||||
return matchingRule;
|
||||
};
|
||||
|
||||
WikiParser.prototype.parseRule = function(rule) {
|
||||
var start = this.pos,
|
||||
blocks = rule.parse(),
|
||||
pending = [];
|
||||
// Estimate start/end ranges for blocks that don't define their own based on
|
||||
// sibling and parent ranges
|
||||
for(var i=0; i<blocks.length; i++) {
|
||||
var block = blocks[i];
|
||||
if(block.start === undefined) {
|
||||
block.start = start;
|
||||
} else {
|
||||
this.applyRangeEnd(pending,block.start);
|
||||
pending.length = 0;
|
||||
}
|
||||
if(block.end === undefined) {
|
||||
pending.push(block);
|
||||
} else {
|
||||
start = block.end;
|
||||
}
|
||||
}
|
||||
this.applyRangeEnd(pending,this.pos);
|
||||
return blocks;
|
||||
};
|
||||
|
||||
WikiParser.prototype.applyRangeEnd = function(blocks,end) {
|
||||
for(var i=0; i<blocks.length; i++) {
|
||||
blocks[i].end = end;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Parse any pragmas at the beginning of a block of parse text
|
||||
*/
|
||||
@ -234,7 +204,7 @@ WikiParser.prototype.parsePragmas = function() {
|
||||
break;
|
||||
}
|
||||
// Process the pragma rule
|
||||
var subTree = this.parseRule(nextMatch.rule);
|
||||
var subTree = nextMatch.rule.parse();
|
||||
if(subTree.length > 0) {
|
||||
// Quick hack; we only cope with a single parse tree node being returned, which is true at the moment
|
||||
currentTreeBranch.push.apply(currentTreeBranch,subTree);
|
||||
@ -258,7 +228,7 @@ WikiParser.prototype.parseBlock = function(terminatorRegExpString) {
|
||||
// Look for a block rule that applies at the current position
|
||||
var nextMatch = this.findNextMatch(this.blockRules,this.pos);
|
||||
if(nextMatch && nextMatch.matchIndex === this.pos) {
|
||||
return this.parseRule(nextMatch.rule);
|
||||
return nextMatch.rule.parse();
|
||||
}
|
||||
// Treat it as a paragraph if we didn't find a block rule
|
||||
var start = this.pos;
|
||||
@ -344,7 +314,7 @@ WikiParser.prototype.parseInlineRunUnterminated = function(options) {
|
||||
this.pos = nextMatch.matchIndex;
|
||||
}
|
||||
// Process the run rule
|
||||
tree.push.apply(tree,this.parseRule(nextMatch.rule));
|
||||
tree.push.apply(tree,nextMatch.rule.parse());
|
||||
// Look for the next run rule
|
||||
nextMatch = this.findNextMatch(this.inlineRules,this.pos);
|
||||
}
|
||||
@ -387,7 +357,7 @@ WikiParser.prototype.parseInlineRunTerminated = function(terminatorRegExp,option
|
||||
this.pos = inlineRuleMatch.matchIndex;
|
||||
}
|
||||
// Process the inline rule
|
||||
tree.push.apply(tree,this.parseRule(inlineRuleMatch.rule));
|
||||
tree.push.apply(tree,inlineRuleMatch.rule.parse());
|
||||
// Look for the next inline rule
|
||||
inlineRuleMatch = this.findNextMatch(this.inlineRules,this.pos);
|
||||
// Look for the next terminator match
|
||||
|
@ -95,7 +95,7 @@ describe("WikiText parser tests", function() {
|
||||
);
|
||||
expect(parse("<div><div attribute={{TiddlerTitle!!field}}>\n\n!some heading</div></div>")).toEqual(
|
||||
|
||||
[ { type : 'element', tag : 'p', start: 0, end: 71, children : [ { type : 'element', start : 0, attributes : { }, tag : 'div', end : 5, isBlock : false, children : [ { type : 'element', start : 5, attributes : { attribute : { start : 9, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 43 } }, tag : 'div', end : 44, isBlock : true, children : [ { type : 'element', tag : 'h1', start : 46, end : 71, attributes : { class : { type : 'string', value : '' } }, children : [ { type : 'text', text : 'some heading</div></div>', start : 47, end : 71 } ] } ] } ] } ] } ]
|
||||
[ { type : 'element', tag : 'p', start: 0, end: 71, children : [ { type : 'element', start : 0, attributes : { }, tag : 'div', end : 5, isBlock : false, children : [ { type : 'element', start : 5, attributes : { attribute : { start : 9, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 43 } }, tag : 'div', end : 44, isBlock : true, children : [ { type : 'element', tag : 'h1', attributes : { class : { type : 'string', value : '' } }, children : [ { type : 'text', text : 'some heading</div></div>', start : 47, end : 71 } ] } ] } ] } ] } ]
|
||||
|
||||
);
|
||||
expect(parse("<div><div attribute={{TiddlerTitle!!field}}>\n!some heading</div></div>")).toEqual(
|
||||
@ -114,7 +114,7 @@ describe("WikiText parser tests", function() {
|
||||
it("should parse macro definitions", function() {
|
||||
expect(parse("\\define myMacro()\nnothing\n\\end\n")).toEqual(
|
||||
|
||||
[ { type : 'set', start : 0, end : 30, attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], params : [ ], isMacroDefinition : true } ]
|
||||
[ { type : 'set', attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], params : [ ], isMacroDefinition : true } ]
|
||||
|
||||
);
|
||||
|
||||
@ -226,7 +226,7 @@ describe("WikiText parser tests", function() {
|
||||
it("should parse horizontal rules", function() {
|
||||
expect(parse("---Not a rule\n\n----\n\nBetween\n\n---")).toEqual(
|
||||
|
||||
[ { type : 'element', tag : 'p', start : 0, end : 13, children : [ { type : 'entity', entity : '—', start : 0, end : 3 }, { type : 'text', text : 'Not a rule', start : 3, end : 13 } ] }, { type : 'element', tag : 'hr', start : 15, end : 20 }, { type : 'element', tag : 'p', start : 21, end : 28, children : [ { type : 'text', text : 'Between', start : 21, end : 28 } ] }, { type : 'element', tag : 'hr', start : 30, end : 33 } ]
|
||||
[ { type : 'element', tag : 'p', start : 0, end : 13, children : [ { type : 'entity', entity : '—' }, { type : 'text', text : 'Not a rule', start : 3, end : 13 } ] }, { type : 'element', tag : 'hr' }, { type : 'element', tag : 'p', start : 21, end : 28, children : [ { type : 'text', text : 'Between', start : 21, end : 28 } ] }, { type : 'element', tag : 'hr' } ]
|
||||
|
||||
);
|
||||
|
||||
@ -235,7 +235,7 @@ describe("WikiText parser tests", function() {
|
||||
it("should parse hard linebreak areas", function() {
|
||||
expect(parse("\"\"\"Something\nin the\nway she moves\n\"\"\"\n\n")).toEqual(
|
||||
|
||||
[ { type : 'element', tag : 'p', children : [ { type : 'text', text : 'Something', start : 3, end : 12 }, { type : 'element', tag : 'br', start : 12, end : 13 }, { type : 'text', text : 'in the', start : 13, end : 19 }, { type : 'element', tag : 'br', start : 19, end : 20 }, { type : 'text', text : 'way she moves', start : 20, end : 33 }, { type : 'element', tag : 'br', start: 33, end: 37 } ], start : 0, end : 37 } ]
|
||||
[ { type : 'element', tag : 'p', children : [ { type : 'text', text : 'Something', start : 3, end : 12 }, { type : 'element', tag : 'br' }, { type : 'text', text : 'in the', start : 13, end : 19 }, { type : 'element', tag : 'br' }, { type : 'text', text : 'way she moves', start : 20, end : 33 }, { type : 'element', tag : 'br' } ], start : 0, end : 37 } ]
|
||||
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user