1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-16 06:44:50 +00:00

Initial Commit

This commit is contained in:
jeremy@jermolene.com 2023-01-05 10:55:35 +00:00
parent 8ca0bf10e4
commit 574b90cf7a
5 changed files with 85 additions and 48 deletions

View File

@ -32,6 +32,7 @@ options: see below:
parseAsInline: true to parse text as inline instead of block parseAsInline: true to parse text as inline instead of block
wiki: reference to wiki to use wiki: reference to wiki to use
_canonical_uri: optional URI of content if text is missing or empty _canonical_uri: optional URI of content if text is missing or empty
title: optional tiddler title to be available within this parse tree via the variable "thisTiddler"
*/ */
var WikiParser = function(type,text,options) { var WikiParser = function(type,text,options) {
this.wiki = options.wiki; this.wiki = options.wiki;
@ -51,8 +52,9 @@ var WikiParser = function(type,text,options) {
this.parseAsInline = options.parseAsInline; this.parseAsInline = options.parseAsInline;
// Set current parse position // Set current parse position
this.pos = 0; this.pos = 0;
// Start with empty output // Start with empty output and initialise insertion point
this.tree = []; this.tree = [];
var topBranch = this.tree;
// Assemble the rule classes we're going to use // Assemble the rule classes we're going to use
var pragmaRuleClasses, blockRuleClasses, inlineRuleClasses; var pragmaRuleClasses, blockRuleClasses, inlineRuleClasses;
if(options.rules) { if(options.rules) {
@ -82,8 +84,19 @@ var WikiParser = function(type,text,options) {
// Instantiate the parser block and inline rules // Instantiate the parser block and inline rules
this.blockRules = this.instantiateRules(blockRuleClasses,"block",0); this.blockRules = this.instantiateRules(blockRuleClasses,"block",0);
this.inlineRules = this.instantiateRules(inlineRuleClasses,"inline",0); this.inlineRules = this.instantiateRules(inlineRuleClasses,"inline",0);
// Set the "thisTiddler" variable
var thisTiddlerAssignment = {
type: "set",
attributes: {
name: {type: "string", value: "thisTiddler"},
value: {type: "string", value: options.title || ""}
},
children: []
};
topBranch.push(thisTiddlerAssignment);
topBranch = thisTiddlerAssignment.children;
// Parse any pragmas // Parse any pragmas
var topBranch = this.parsePragmas(); topBranch = this.parsePragmas(topBranch);
// Parse the text into inline runs or blocks // Parse the text into inline runs or blocks
if(this.parseAsInline) { if(this.parseAsInline) {
topBranch.push.apply(topBranch,this.parseInlineRun()); topBranch.push.apply(topBranch,this.parseInlineRun());
@ -190,8 +203,8 @@ WikiParser.prototype.findNextMatch = function(rules,startPos) {
/* /*
Parse any pragmas at the beginning of a block of parse text Parse any pragmas at the beginning of a block of parse text
*/ */
WikiParser.prototype.parsePragmas = function() { WikiParser.prototype.parsePragmas = function(targetParseTreeNodes) {
var currentTreeBranch = this.tree; var currentTreeBranch = targetParseTreeNodes || this.tree;
while(true) { while(true) {
// Skip whitespace // Skip whitespace
this.skipWhitespace(); this.skipWhitespace();

View File

@ -969,6 +969,7 @@ Parse a block of text of a specified MIME type
Options include: Options include:
parseAsInline: if true, the text of the tiddler will be parsed as an inline run parseAsInline: if true, the text of the tiddler will be parsed as an inline run
_canonical_uri: optional string of the canonical URI of this content _canonical_uri: optional string of the canonical URI of this content
title: optional tiddler title to be available within this parse tree via the variable "thisTiddler"
*/ */
exports.parseText = function(type,text,options) { exports.parseText = function(type,text,options) {
text = text || ""; text = text || "";
@ -988,7 +989,8 @@ exports.parseText = function(type,text,options) {
return new Parser(type,text,{ return new Parser(type,text,{
parseAsInline: options.parseAsInline, parseAsInline: options.parseAsInline,
wiki: this, wiki: this,
_canonical_uri: options._canonical_uri _canonical_uri: options._canonical_uri,
title: options.title
}); });
}; };
@ -996,7 +998,9 @@ exports.parseText = function(type,text,options) {
Parse a tiddler according to its MIME type Parse a tiddler according to its MIME type
*/ */
exports.parseTiddler = function(title,options) { exports.parseTiddler = function(title,options) {
options = $tw.utils.extend({},options); options = $tw.utils.extend({
title: title
},options);
var cacheType = options.parseAsInline ? "inlineParseTree" : "blockParseTree", var cacheType = options.parseAsInline ? "inlineParseTree" : "blockParseTree",
tiddler = this.getTiddler(title), tiddler = this.getTiddler(title),
self = this; self = this;

View File

@ -0,0 +1,20 @@
title: ThisTiddler/Simple
description: Simple usage of thisTiddler variable
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
\define print-this-tiddler()
<$text text={{{ [<thisTiddler>!is[blank]else[**MISSING**]] }}}/>
\end
(<$text text={{{ [<thisTiddler>!is[blank]else[**MISSING**]] }}}/>)
(<<print-this-tiddler>>)
+
title: ExpectedResult
<p>(Output)</p><p>(**MISSING**)</p>

View File

@ -772,7 +772,7 @@ describe("Widget module", function() {
var parseTreeNode = parseText(text,wiki); var parseTreeNode = parseText(text,wiki);
// Test the resulting parse tree node, since there is no // Test the resulting parse tree node, since there is no
// rendering which may expose a problem. // rendering which may expose a problem.
expect(parseTreeNode.children[0].attributes.filter.value).toBe('[prefix[XXX]]'); expect(parseTreeNode.children[0].children[0].attributes.filter.value).toBe('[prefix[XXX]]');
}); });
/** This test reproduces issue #4504. /** This test reproduces issue #4504.

View File

@ -25,88 +25,88 @@ describe("WikiText parser tests", function() {
it("should parse tags", function() { it("should parse tags", function() {
expect(parse("<br>")).toEqual( expect(parse("<br>")).toEqual(
[ { type : 'element', tag : 'p', start : 0, end : 4, children : [ { type : 'element', tag : 'br', start : 0, end : 4, isBlock : false, attributes : { }, orderedAttributes: [ ] } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start : 0, end : 4, children : [ { type : 'element', tag : 'br', start : 0, end : 4, isBlock : false, attributes : { }, orderedAttributes: [ ] } ] } ] } ]
); );
expect(parse("</br>")).toEqual( expect(parse("</br>")).toEqual(
[ { type : 'element', tag : 'p', start : 0, end : 5, children : [ { type : 'text', text : '</br>', start : 0, end : 5 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start : 0, end : 5, children : [ { type : 'text', text : '</br>', start : 0, end : 5 } ] } ] } ]
); );
expect(parse("<div>")).toEqual( expect(parse("<div>")).toEqual(
[ { type : 'element', tag : 'p', start : 0, end : 5, children : [ { type : 'element', tag : 'div', start : 0, end : 5, isBlock : false, attributes : { }, orderedAttributes: [ ], children : [ ] } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start : 0, end : 5, children : [ { type : 'element', tag : 'div', start : 0, end : 5, isBlock : false, attributes : { }, orderedAttributes: [ ], children : [ ] } ] } ] } ]
); );
expect(parse("<div/>")).toEqual( expect(parse("<div/>")).toEqual(
[ { type : 'element', tag : 'p', start : 0, end : 6, children : [ { type : 'element', tag : 'div', isSelfClosing : true, isBlock : false, attributes : { }, orderedAttributes: [ ], start : 0, end : 6 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start : 0, end : 6, children : [ { type : 'element', tag : 'div', isSelfClosing : true, isBlock : false, attributes : { }, orderedAttributes: [ ], start : 0, end : 6 } ] } ] } ]
); );
expect(parse("<div></div>")).toEqual( expect(parse("<div></div>")).toEqual(
[ { type : 'element', tag : 'p', start : 0, end : 11, children : [ { type : 'element', tag : 'div', isBlock : false, attributes : { }, orderedAttributes: [ ], children : [ ], start : 0, end : 5 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start : 0, end : 11, children : [ { type : 'element', tag : 'div', isBlock : false, attributes : { }, orderedAttributes: [ ], children : [ ], start : 0, end : 5 } ] } ] } ]
); );
expect(parse("<div>some text</div>")).toEqual( expect(parse("<div>some text</div>")).toEqual(
[ { type : 'element', tag : 'p', start : 0, end : 20, children : [ { type : 'element', tag : 'div', start : 0, end : 20, isBlock : false, attributes : { }, orderedAttributes: [ ], children : [ { type : 'text', text : 'some text', start : 5, end : 14 } ], start : 0, end : 5 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start : 0, end : 20, children : [ { type : 'element', tag : 'div', start : 0, end : 20, isBlock : false, attributes : { }, orderedAttributes: [ ], children : [ { type : 'text', text : 'some text', start : 5, end : 14 } ], start : 0, end : 5 } ] } ] } ]
); );
expect(parse("<div attribute>some text</div>")).toEqual( expect(parse("<div attribute>some text</div>")).toEqual(
[ { type : 'element', tag : 'p', start : 0, end : 30, children : [ { type : 'element', tag : 'div', isBlock : false, attributes : { attribute : { type : 'string', value : 'true', start : 4, end : 14, name: 'attribute' } }, orderedAttributes: [ { type : 'string', value : 'true', start : 4, end : 14, name: 'attribute' } ], children : [ { type : 'text', text : 'some text', start : 15, end : 24 } ], start : 0, end : 15 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start : 0, end : 30, children : [ { type : 'element', tag : 'div', isBlock : false, attributes : { attribute : { type : 'string', value : 'true', start : 4, end : 14, name: 'attribute' } }, orderedAttributes: [ { type : 'string', value : 'true', start : 4, end : 14, name: 'attribute' } ], children : [ { type : 'text', text : 'some text', start : 15, end : 24 } ], start : 0, end : 15 } ] } ] } ]
); );
expect(parse("<div attribute='value'>some text</div>")).toEqual( expect(parse("<div attribute='value'>some text</div>")).toEqual(
[ { type : 'element', tag : 'p', start : 0, end : 38, children : [ { type : 'element', tag : 'div', start: 0, end: 38, isBlock : false, attributes : { attribute : { type : 'string', name: 'attribute', value : 'value', start: 4, end: 22 } }, orderedAttributes: [ { type: 'string', name: 'attribute', value : 'value', start: 4, end: 22 } ], children : [ { type : 'text', text : 'some text', start : 23, end : 32 } ], start : 0, end : 23 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start : 0, end : 38, children : [ { type : 'element', tag : 'div', start: 0, end: 38, isBlock : false, attributes : { attribute : { type : 'string', name: 'attribute', value : 'value', start: 4, end: 22 } }, orderedAttributes: [ { type: 'string', name: 'attribute', value : 'value', start: 4, end: 22 } ], children : [ { type : 'text', text : 'some text', start : 23, end : 32 } ], start : 0, end : 23 } ] } ] } ]
); );
expect(parse("<div attribute={{TiddlerTitle}}>some text</div>")).toEqual( expect(parse("<div attribute={{TiddlerTitle}}>some text</div>")).toEqual(
[ { type : 'element', tag : 'p', start: 0, end: 47, children : [ { type : 'element', tag : 'div', isBlock : false, attributes : { attribute : { type : 'indirect', name: 'attribute', textReference : 'TiddlerTitle', start : 4, end : 31 } }, orderedAttributes: [ { type : 'indirect', name: 'attribute', textReference : 'TiddlerTitle', start : 4, end : 31 } ], children : [ { type : 'text', text : 'some text', start : 32, end : 41 } ], start : 0, end : 32 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start: 0, end: 47, children : [ { type : 'element', tag : 'div', isBlock : false, attributes : { attribute : { type : 'indirect', name: 'attribute', textReference : 'TiddlerTitle', start : 4, end : 31 } }, orderedAttributes: [ { type : 'indirect', name: 'attribute', textReference : 'TiddlerTitle', start : 4, end : 31 } ], children : [ { type : 'text', text : 'some text', start : 32, end : 41 } ], start : 0, end : 32 } ] } ] } ]
); );
expect(parse("<$reveal state='$:/temp/search' type='nomatch' text=''>")).toEqual( expect(parse("<$reveal state='$:/temp/search' type='nomatch' text=''>")).toEqual(
[ { type : 'element', tag : 'p', start: 0, end: 55, children : [ { type : 'reveal', tag: '$reveal', start : 0, attributes : { state : { start : 8, name : 'state', type : 'string', value : '$:/temp/search', end : 31 }, type : { start : 31, name : 'type', type : 'string', value : 'nomatch', end : 46 }, text : { start : 46, name : 'text', type : 'string', value : '', end : 54 } }, orderedAttributes: [ { start : 8, name : 'state', type : 'string', value : '$:/temp/search', end : 31 }, { start : 31, name : 'type', type : 'string', value : 'nomatch', end : 46 }, { start : 46, name : 'text', type : 'string', value : '', end : 54 } ], end : 55, isBlock : false, children : [ ] } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start: 0, end: 55, children : [ { type : 'reveal', tag: '$reveal', start : 0, attributes : { state : { start : 8, name : 'state', type : 'string', value : '$:/temp/search', end : 31 }, type : { start : 31, name : 'type', type : 'string', value : 'nomatch', end : 46 }, text : { start : 46, name : 'text', type : 'string', value : '', end : 54 } }, orderedAttributes: [ { start : 8, name : 'state', type : 'string', value : '$:/temp/search', end : 31 }, { start : 31, name : 'type', type : 'string', value : 'nomatch', end : 46 }, { start : 46, name : 'text', type : 'string', value : '', end : 54 } ], end : 55, isBlock : false, children : [ ] } ] } ] } ]
); );
expect(parse("<div attribute={{TiddlerTitle!!field}}>some text</div>")).toEqual( expect(parse("<div attribute={{TiddlerTitle!!field}}>some text</div>")).toEqual(
[ { type : 'element', tag : 'p', start: 0, end: 54, children : [ { type : 'element', tag : 'div', isBlock : false, attributes : { attribute : { type : 'indirect', name : 'attribute', textReference : 'TiddlerTitle!!field', start : 4, end : 38 } }, orderedAttributes: [ { type : 'indirect', name : 'attribute', textReference : 'TiddlerTitle!!field', start : 4, end : 38 } ], children : [ { type : 'text', text : 'some text', start : 39, end : 48 } ], start : 0, end : 39 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start: 0, end: 54, children : [ { type : 'element', tag : 'div', isBlock : false, attributes : { attribute : { type : 'indirect', name : 'attribute', textReference : 'TiddlerTitle!!field', start : 4, end : 38 } }, orderedAttributes: [ { type : 'indirect', name : 'attribute', textReference : 'TiddlerTitle!!field', start : 4, end : 38 } ], children : [ { type : 'text', text : 'some text', start : 39, end : 48 } ], start : 0, end : 39 } ] } ] } ]
); );
expect(parse("<div attribute={{Tiddler Title!!field}}>some text</div>")).toEqual( expect(parse("<div attribute={{Tiddler Title!!field}}>some text</div>")).toEqual(
[ { type : 'element', tag : 'p', start: 0, end: 55, children : [ { type : 'element', tag : 'div', isBlock : false, attributes : { attribute : { type : 'indirect', name : 'attribute', textReference : 'Tiddler Title!!field', start : 4, end : 39 } }, orderedAttributes: [ { type : 'indirect', name : 'attribute', textReference : 'Tiddler Title!!field', start : 4, end : 39 } ], children : [ { type : 'text', text : 'some text', start : 40, end : 49 } ], start : 0, end : 40 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start: 0, end: 55, children : [ { type : 'element', tag : 'div', isBlock : false, attributes : { attribute : { type : 'indirect', name : 'attribute', textReference : 'Tiddler Title!!field', start : 4, end : 39 } }, orderedAttributes: [ { type : 'indirect', name : 'attribute', textReference : 'Tiddler Title!!field', start : 4, end : 39 } ], children : [ { type : 'text', text : 'some text', start : 40, end : 49 } ], start : 0, end : 40 } ] } ] } ]
); );
expect(parse("<div attribute={{TiddlerTitle!!field}}>\n\nsome text</div>")).toEqual( expect(parse("<div attribute={{TiddlerTitle!!field}}>\n\nsome text</div>")).toEqual(
[ { type : 'element', start : 0, attributes : { attribute : { start : 4, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 38 } }, orderedAttributes: [ { start : 4, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 38 } ], tag : 'div', end : 39, isBlock : true, children : [ { type : 'element', tag : 'p', start : 41, end : 50, children : [ { type : 'text', text : 'some text', start : 41, end : 50 } ] } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', start : 0, attributes : { attribute : { start : 4, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 38 } }, orderedAttributes: [ { start : 4, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 38 } ], tag : 'div', end : 39, isBlock : true, children : [ { type : 'element', tag : 'p', start : 41, end : 50, children : [ { type : 'text', text : 'some text', start : 41, end : 50 } ] } ] } ] } ]
); );
expect(parse("<div><div attribute={{TiddlerTitle!!field}}>\n\nsome text</div></div>")).toEqual( expect(parse("<div><div attribute={{TiddlerTitle!!field}}>\n\nsome text</div></div>")).toEqual(
[ { type : 'element', tag : 'p', start: 0, end: 67, children : [ { type : 'element', start : 0, attributes : { }, orderedAttributes: [ ], tag : 'div', end : 5, isBlock : false, children : [ { type : 'element', start : 5, attributes : { attribute : { start : 9, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 43 } }, orderedAttributes: [ { start : 9, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 43 } ], tag : 'div', end : 44, isBlock : true, children : [ { type : 'element', tag : 'p', start : 46, end : 55, children : [ { type : 'text', text : 'some text', start : 46, end : 55 } ] } ] } ] } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start: 0, end: 67, children : [ { type : 'element', start : 0, attributes : { }, orderedAttributes: [ ], tag : 'div', end : 5, isBlock : false, children : [ { type : 'element', start : 5, attributes : { attribute : { start : 9, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 43 } }, orderedAttributes: [ { start : 9, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 43 } ], tag : 'div', end : 44, isBlock : true, children : [ { type : 'element', tag : 'p', start : 46, end : 55, children : [ { type : 'text', text : 'some text', start : 46, end : 55 } ] } ] } ] } ] } ] } ]
); );
expect(parse("<div><div attribute={{TiddlerTitle!!field}}>\n\n!some heading</div></div>")).toEqual( 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 : { }, orderedAttributes: [ ], tag : 'div', end : 5, isBlock : false, children : [ { type : 'element', start : 5, attributes : { attribute : { start : 9, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 43 } }, orderedAttributes: [ { 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 } ] } ] } ] } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start: 0, end: 71, children : [ { type : 'element', start : 0, attributes : { }, orderedAttributes: [ ], tag : 'div', end : 5, isBlock : false, children : [ { type : 'element', start : 5, attributes : { attribute : { start : 9, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 43 } }, orderedAttributes: [ { 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( expect(parse("<div><div attribute={{TiddlerTitle!!field}}>\n!some heading</div></div>")).toEqual(
[ { type : 'element', tag : 'p', start: 0, end: 70, children : [ { type : 'element', start : 0, attributes : { }, orderedAttributes: [ ], tag : 'div', end : 5, isBlock : false, children : [ { type : 'element', start : 5, attributes : { attribute : { start : 9, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 43 } }, orderedAttributes: [ { start : 9, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 43 } ], tag : 'div', end : 44, isBlock : false, children : [ { type : 'text', text : '\n!some heading', start : 44, end : 58 } ] } ] } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start: 0, end: 70, children : [ { type : 'element', start : 0, attributes : { }, orderedAttributes: [ ], tag : 'div', end : 5, isBlock : false, children : [ { type : 'element', start : 5, attributes : { attribute : { start : 9, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 43 } }, orderedAttributes: [ { start : 9, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 43 } ], tag : 'div', end : 44, isBlock : false, children : [ { type : 'text', text : '\n!some heading', start : 44, end : 58 } ] } ] } ] } ] } ]
); );
// Regression test for issue (#3306) // Regression test for issue (#3306)
expect(parse("<div><span><span>\n\nSome text</span></span></div>")).toEqual( expect(parse("<div><span><span>\n\nSome text</span></span></div>")).toEqual(
[ { type : 'element', tag : 'p', start: 0, end: 48, children : [ { type : 'element', start : 0, attributes : { }, orderedAttributes: [ ], tag : 'div', end : 5, isBlock : false, children : [ { type : 'element', start : 5, attributes : { }, orderedAttributes: [ ], tag : 'span', end : 11, isBlock : false, children : [ { type : 'element', start : 11, attributes : { }, orderedAttributes: [ ], tag : 'span', end : 17, isBlock : true, children : [ { type : 'element', tag : 'p', start : 19, end : 28, children : [ { type : 'text', text : 'Some text', start : 19, end : 28 } ] } ] } ] } ] } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start: 0, end: 48, children : [ { type : 'element', start : 0, attributes : { }, orderedAttributes: [ ], tag : 'div', end : 5, isBlock : false, children : [ { type : 'element', start : 5, attributes : { }, orderedAttributes: [ ], tag : 'span', end : 11, isBlock : false, children : [ { type : 'element', start : 11, attributes : { }, orderedAttributes: [ ], tag : 'span', end : 17, isBlock : true, children : [ { type : 'element', tag : 'p', start : 19, end : 28, children : [ { type : 'text', text : 'Some text', start : 19, end : 28 } ] } ] } ] } ] } ] } ] } ]
); );
}); });
@ -114,7 +114,7 @@ describe("WikiText parser tests", function() {
it("should parse macro definitions", function() { it("should parse macro definitions", function() {
expect(parse("\\define myMacro()\nnothing\n\\end\n")).toEqual( expect(parse("\\define myMacro()\nnothing\n\\end\n")).toEqual(
[ { type : 'set', attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], params : [ ], isMacroDefinition : true } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'set', attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], params : [ ], isMacroDefinition : true } ] } ]
); );
}); });
@ -122,7 +122,7 @@ describe("WikiText parser tests", function() {
it("should parse comment in pragma area. Comment will be invisible", function() { it("should parse comment in pragma area. Comment will be invisible", function() {
expect(parse("<!-- comment in pragma area -->\n\\define aMacro()\nnothing\n\\end\n")).toEqual( expect(parse("<!-- comment in pragma area -->\n\\define aMacro()\nnothing\n\\end\n")).toEqual(
[ { type : 'set', attributes : { name : { type : 'string', value : 'aMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], params : [ ], isMacroDefinition : true } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'set', attributes : { name : { type : 'string', value : 'aMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], params : [ ], isMacroDefinition : true } ] } ]
); );
}); });
@ -130,12 +130,12 @@ describe("WikiText parser tests", function() {
it("should block mode filtered transclusions", function() { it("should block mode filtered transclusions", function() {
expect(parse("{{{ filter }}}")).toEqual( expect(parse("{{{ filter }}}")).toEqual(
[ { type: 'list', attributes: { filter: { type: 'string', value: ' filter ' } }, isBlock: true } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'list', attributes: { filter: { type: 'string', value: ' filter ' } }, isBlock: true } ] } ]
); );
expect(parse("{{{ fil\nter }}}")).toEqual( expect(parse("{{{ fil\nter }}}")).toEqual(
[ { type: 'list', attributes: { filter: { type: 'string', value: ' fil\nter ' } }, isBlock: true } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'list', attributes: { filter: { type: 'string', value: ' fil\nter ' } }, isBlock: true } ] } ]
); );
}); });
@ -143,38 +143,38 @@ describe("WikiText parser tests", function() {
it("should parse inline macro calls", function() { it("should parse inline macro calls", function() {
expect(parse("<<john>><<paul>><<george>><<ringo>>")).toEqual( expect(parse("<<john>><<paul>><<george>><<ringo>>")).toEqual(
[ { type: 'element', tag: 'p', start: 0, end: 35, children: [ { type: 'macrocall', start: 0, params: [ ], name: 'john', end: 8 }, { type: 'macrocall', start: 8, params: [ ], name: 'paul', end: 16 }, { type: 'macrocall', start: 16, params: [ ], name: 'george', end: 26 }, { type: 'macrocall', start: 26, params: [ ], name: 'ringo', end: 35 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'element', tag: 'p', start: 0, end: 35, children: [ { type: 'macrocall', start: 0, params: [ ], name: 'john', end: 8 }, { type: 'macrocall', start: 8, params: [ ], name: 'paul', end: 16 }, { type: 'macrocall', start: 16, params: [ ], name: 'george', end: 26 }, { type: 'macrocall', start: 26, params: [ ], name: 'ringo', end: 35 } ] } ] } ]
); );
expect(parse("text <<john one:val1 two: 'val \"2\"' three: \"val '3'\" four: \"\"\"val 4\"5'\"\"\" five: [[val 5]] >>")).toEqual( expect(parse("text <<john one:val1 two: 'val \"2\"' three: \"val '3'\" four: \"\"\"val 4\"5'\"\"\" five: [[val 5]] >>")).toEqual(
[{ type: 'element', tag: 'p', start: 0, end: 92, children: [ { type: 'text', text: 'text ', start: 0, end: 5 }, { type: 'macrocall', name: 'john', start: 5, params: [ { type: 'macro-parameter', start: 11, value: 'val1', name: 'one', end: 20 }, { type: 'macro-parameter', start: 20, value: 'val "2"', name: 'two', end: 35 }, { type: 'macro-parameter', start: 35, value: 'val \'3\'', name: 'three', end: 52 }, { type: 'macro-parameter', start: 52, value: 'val 4"5\'', name: 'four', end: 73 }, { type: 'macro-parameter', start: 73, value: 'val 5', name: 'five', end: 89 } ], end: 92 } ] } ] [{ type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'element', tag: 'p', start: 0, end: 92, children: [ { type: 'text', text: 'text ', start: 0, end: 5 }, { type: 'macrocall', name: 'john', start: 5, params: [ { type: 'macro-parameter', start: 11, value: 'val1', name: 'one', end: 20 }, { type: 'macro-parameter', start: 20, value: 'val "2"', name: 'two', end: 35 }, { type: 'macro-parameter', start: 35, value: 'val \'3\'', name: 'three', end: 52 }, { type: 'macro-parameter', start: 52, value: 'val 4"5\'', name: 'four', end: 73 }, { type: 'macro-parameter', start: 73, value: 'val 5', name: 'five', end: 89 } ], end: 92 } ] } ] } ]
); );
expect(parse("ignored << carrots <<john>>")).toEqual( expect(parse("ignored << carrots <<john>>")).toEqual(
[ { type: 'element', tag: 'p', start: 0, end: 27, children: [ { type: 'text', text: 'ignored << carrots ', start: 0, end: 19 }, { type: 'macrocall', name: 'john', start: 19, params: [ ], end: 27 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'element', tag: 'p', start: 0, end: 27, children: [ { type: 'text', text: 'ignored << carrots ', start: 0, end: 19 }, { type: 'macrocall', name: 'john', start: 19, params: [ ], end: 27 } ] } ] } ]
); );
expect(parse("text <<<john>>")).toEqual( expect(parse("text <<<john>>")).toEqual(
[ { type: 'element', tag: 'p', start: 0, end: 14, children: [ { type: 'text', text: 'text ', start: 0, end: 5 }, { type: 'macrocall', name: '<john', start: 5, params: [ ], end: 14 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'element', tag: 'p', start: 0, end: 14, children: [ { type: 'text', text: 'text ', start: 0, end: 5 }, { type: 'macrocall', name: '<john', start: 5, params: [ ], end: 14 } ] } ] } ]
); );
expect(parse("before\n<<john>>")).toEqual( expect(parse("before\n<<john>>")).toEqual(
[ { type: 'element', tag: 'p', start: 0, end: 15, children: [ { type: 'text', text: 'before\n', start: 0, end: 7 }, { type: 'macrocall', start: 7, params: [ ], name: 'john', end: 15 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'element', tag: 'p', start: 0, end: 15, children: [ { type: 'text', text: 'before\n', start: 0, end: 7 }, { type: 'macrocall', start: 7, params: [ ], name: 'john', end: 15 } ] } ] } ]
); );
// A single space will cause it to be inline // A single space will cause it to be inline
expect(parse("<<john>> ")).toEqual( expect(parse("<<john>> ")).toEqual(
[ { type: 'element', tag: 'p', start: 0, end: 9, children: [ { type: 'macrocall', start: 0, params: [ ], name: 'john', end: 8 }, { type: 'text', text: ' ', start: 8, end: 9 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'element', tag: 'p', start: 0, end: 9, children: [ { type: 'macrocall', start: 0, params: [ ], name: 'john', end: 8 }, { type: 'text', text: ' ', start: 8, end: 9 } ] } ] } ]
); );
expect(parse("text <<outie one:'my <<innie>>' >>")).toEqual( expect(parse("text <<outie one:'my <<innie>>' >>")).toEqual(
[ { type: 'element', tag: 'p', start: 0, end: 34, children: [ { type: 'text', text: 'text ', start: 0, end: 5 }, { type: 'macrocall', start: 5, params: [ { type: 'macro-parameter', start: 12, value: 'my <<innie>>', name: 'one', end: 31 } ], name: 'outie', end: 34 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'element', tag: 'p', start: 0, end: 34, children: [ { type: 'text', text: 'text ', start: 0, end: 5 }, { type: 'macrocall', start: 5, params: [ { type: 'macro-parameter', start: 12, value: 'my <<innie>>', name: 'one', end: 31 } ], name: 'outie', end: 34 } ] } ] } ]
); );
@ -183,37 +183,37 @@ describe("WikiText parser tests", function() {
it("should parse block macro calls", function() { it("should parse block macro calls", function() {
expect(parse("<<john>>\n<<paul>>\r\n<<george>>\n<<ringo>>")).toEqual( expect(parse("<<john>>\n<<paul>>\r\n<<george>>\n<<ringo>>")).toEqual(
[ { type: 'macrocall', start: 0, name: 'john', params: [ ], end: 8, isBlock: true }, { type: 'macrocall', start: 9, name: 'paul', params: [ ], end: 17, isBlock: true }, { type: 'macrocall', start: 19, name: 'george', params: [ ], end: 29, isBlock: true }, { type: 'macrocall', start: 30, name: 'ringo', params: [ ], end: 39, isBlock: true } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'macrocall', start: 0, name: 'john', params: [ ], end: 8, isBlock: true }, { type: 'macrocall', start: 9, name: 'paul', params: [ ], end: 17, isBlock: true }, { type: 'macrocall', start: 19, name: 'george', params: [ ], end: 29, isBlock: true }, { type: 'macrocall', start: 30, name: 'ringo', params: [ ], end: 39, isBlock: true } ] } ]
); );
expect(parse("<<john one:val1 two: 'val \"2\"' three: \"val '3'\" four: \"\"\"val 4\"5'\"\"\" five: [[val 5]] >>")).toEqual( expect(parse("<<john one:val1 two: 'val \"2\"' three: \"val '3'\" four: \"\"\"val 4\"5'\"\"\" five: [[val 5]] >>")).toEqual(
[ { type: 'macrocall', start: 0, name: 'john', params: [ { type: 'macro-parameter', start: 6, value: 'val1', name: 'one', end: 15 }, { type: 'macro-parameter', start: 15, value: 'val "2"', name: 'two', end: 30 }, { type: 'macro-parameter', start: 30, value: 'val \'3\'', name: 'three', end: 47 }, { type: 'macro-parameter', start: 47, value: 'val 4"5\'', name: 'four', end: 68 }, { type: 'macro-parameter', start: 68, value: 'val 5', name: 'five', end: 84 }], end: 87, isBlock: true } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'macrocall', start: 0, name: 'john', params: [ { type: 'macro-parameter', start: 6, value: 'val1', name: 'one', end: 15 }, { type: 'macro-parameter', start: 15, value: 'val "2"', name: 'two', end: 30 }, { type: 'macro-parameter', start: 30, value: 'val \'3\'', name: 'three', end: 47 }, { type: 'macro-parameter', start: 47, value: 'val 4"5\'', name: 'four', end: 68 }, { type: 'macro-parameter', start: 68, value: 'val 5', name: 'five', end: 84 }], end: 87, isBlock: true } ] } ]
); );
expect(parse("<< carrots\n\n<<john>>")).toEqual( expect(parse("<< carrots\n\n<<john>>")).toEqual(
[ { type: 'element', tag: 'p', start : 0, end : 10, children: [ { type: 'text', text: '<< carrots', start : 0, end : 10 } ] }, { type: 'macrocall', start: 12, params: [ ], name: 'john', end: 20, isBlock: true } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'element', tag: 'p', start : 0, end : 10, children: [ { type: 'text', text: '<< carrots', start : 0, end : 10 } ] }, { type: 'macrocall', start: 12, params: [ ], name: 'john', end: 20, isBlock: true } ] } ]
); );
expect(parse("before\n\n<<john>>")).toEqual( expect(parse("before\n\n<<john>>")).toEqual(
[ { type: 'element', tag: 'p', start : 0, end : 6, children: [ { type: 'text', text: 'before', start : 0, end : 6 } ] }, { type: 'macrocall', start: 8, name: 'john', params: [ ], end: 16, isBlock: true } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'element', tag: 'p', start : 0, end : 6, children: [ { type: 'text', text: 'before', start : 0, end : 6 } ] }, { type: 'macrocall', start: 8, name: 'john', params: [ ], end: 16, isBlock: true } ] } ]
); );
expect(parse("<<john>>\nafter")).toEqual( expect(parse("<<john>>\nafter")).toEqual(
[ { type: 'macrocall', start: 0, name: 'john', params: [ ], end: 8, isBlock: true }, { type: 'element', tag: 'p', start: 9, end: 14, children: [ { type: 'text', text: 'after', start: 9, end: 14 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'macrocall', start: 0, name: 'john', params: [ ], end: 8, isBlock: true }, { type: 'element', tag: 'p', start: 9, end: 14, children: [ { type: 'text', text: 'after', start: 9, end: 14 } ] } ] } ]
); );
expect(parse("<<multiline arg:\"\"\"\n\nwikitext\n\"\"\" >>")).toEqual( expect(parse("<<multiline arg:\"\"\"\n\nwikitext\n\"\"\" >>")).toEqual(
[ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 11, value: '\n\nwikitext\n', name: 'arg', end: 33 } ], name: 'multiline', end: 36, isBlock: true }] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 11, value: '\n\nwikitext\n', name: 'arg', end: 33 } ], name: 'multiline', end: 36, isBlock: true } ] } ]
); );
expect(parse("<<outie one:'my <<innie>>' >>")).toEqual( expect(parse("<<outie one:'my <<innie>>' >>")).toEqual(
[ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 7, value: 'my <<innie>>', name: 'one', end: 26 } ], name: 'outie', end: 29, isBlock: true } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 7, value: 'my <<innie>>', name: 'one', end: 26 } ], name: 'outie', end: 29, isBlock: true } ] } ]
); );
}); });
@ -221,23 +221,23 @@ describe("WikiText parser tests", function() {
it("should parse tricky macrocall parameters", function() { it("should parse tricky macrocall parameters", function() {
expect(parse("<<john pa>am>>")).toEqual( expect(parse("<<john pa>am>>")).toEqual(
[ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 6, value: 'pa>am', end: 12 } ], name: 'john', end: 14, isBlock: true } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 6, value: 'pa>am', end: 12 } ], name: 'john', end: 14, isBlock: true } ] } ]
); );
expect(parse("<<john param> >>")).toEqual( expect(parse("<<john param> >>")).toEqual(
[ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 6, value: 'param>', end: 13 } ], name: 'john', end: 16, isBlock: true } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 6, value: 'param>', end: 13 } ], name: 'john', end: 16, isBlock: true } ] } ]
); );
expect(parse("<<john param>>>")).toEqual( expect(parse("<<john param>>>")).toEqual(
[ { type: 'element', tag: 'p', start: 0, end: 15, children: [ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 6, value: 'param', end: 12 } ], name: 'john', end: 14 }, { type: 'text', text: '>', start: 14, end: 15 } ] } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'element', tag: 'p', start: 0, end: 15, children: [ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 6, value: 'param', end: 12 } ], name: 'john', end: 14 }, { type: 'text', text: '>', start: 14, end: 15 } ] } ] } ]
); );
// equals signs should be allowed // equals signs should be allowed
expect(parse("<<john var>=4 >>")).toEqual( expect(parse("<<john var>=4 >>")).toEqual(
[ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 6, value: 'var>=4', end: 13 } ], name: 'john', end: 16, isBlock: true } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 6, value: 'var>=4', end: 13 } ], name: 'john', end: 16, isBlock: true } ] } ]
); );
@ -246,7 +246,7 @@ describe("WikiText parser tests", function() {
it("should parse horizontal rules", function() { it("should parse horizontal rules", function() {
expect(parse("---Not a rule\n\n----\n\nBetween\n\n---")).toEqual( expect(parse("---Not a rule\n\n----\n\nBetween\n\n---")).toEqual(
[ { type : 'element', tag : 'p', start : 0, end : 13, children : [ { type : 'entity', entity : '&mdash;' }, { 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' } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { type : 'element', tag : 'p', start : 0, end : 13, children : [ { type : 'entity', entity : '&mdash;' }, { 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' } ] } ]
); );
@ -255,7 +255,7 @@ describe("WikiText parser tests", function() {
it("should parse hard linebreak areas", function() { it("should parse hard linebreak areas", function() {
expect(parse("\"\"\"Something\nin the\nway she moves\n\"\"\"\n\n")).toEqual( 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' }, { 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 } ] [ { type : 'set', attributes : { name : { type : 'string', value : 'thisTiddler' }, value : { type : 'string', value : '' } }, children : [ { 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 } ] } ]
); );