Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
37338b1
refactor: extract a new $tw.wiki.getParser
linonetwo Jun 12, 2024
8a12498
feat: allow $tw.utils.getParseTreeText to render other rules' text
linonetwo Jun 12, 2024
09c2e71
feat: two example getText handler
linonetwo Jun 12, 2024
a0708a1
Revert "feat: allow $tw.utils.getParseTreeText to render other rules'…
linonetwo Jun 12, 2024
f882cbd
refactor: keep original getParseTreeText not touched
linonetwo Jun 12, 2024
be3f037
refactor: use serialize in rules
linonetwo Jun 12, 2024
4ddcbc6
Merge remote-tracking branch 'upstream/master' into feat/to-string
linonetwo Jul 29, 2024
4e896d1
refactor: $tw.utils.extend({},options) -> options || {}
linonetwo Jul 29, 2024
179651a
Update codeinline.js
linonetwo Jul 29, 2024
8cbf855
Create test-wikitext-serialize.js
linonetwo Jul 29, 2024
a075303
DEBUG: only run my tests for development, remove before PR merge
linonetwo Jul 29, 2024
05dec72
lint: if
linonetwo Jul 29, 2024
1a6a071
feat: add rule: 'parseBlock' metadata
linonetwo Jul 29, 2024
84e27c0
feat: handle tailing \n that may be missing
linonetwo Jul 29, 2024
078967c
feat: allow recursive
linonetwo Jul 29, 2024
2aff9fe
feat: generate more rule and tests
linonetwo Aug 1, 2024
bfd116a
feat: generate more rule and tests
linonetwo Aug 2, 2024
d067871
fix: remove pragma:true, otherwise following text will become childre…
linonetwo Aug 2, 2024
b1667ec
fix: condition manually
linonetwo Aug 2, 2024
e49238d
fix: some test
linonetwo Aug 2, 2024
383e1b6
fix: some test
linonetwo Aug 2, 2024
63613ce
feat: $tw.utils.serializeAttribute
linonetwo Aug 3, 2024
7b4ea47
fix: use "" for string param
linonetwo Aug 3, 2024
f69795c
feat: list
linonetwo Aug 3, 2024
9df36a2
refactor: ' -> "
linonetwo Aug 3, 2024
2a75077
fix: parsemode don't have node
linonetwo Aug 3, 2024
c392976
fix: render invisible comment and parsemode as data element
linonetwo Aug 3, 2024
b22ca2b
feat: add void: true, in ast node to prevent render
linonetwo Aug 4, 2024
96adee9
Merge branch 'TiddlyWiki:master' into feat/to-string
linonetwo Aug 4, 2024
5b2c3db
feat: use void widget, so methods always return a widget
linonetwo Aug 4, 2024
7bc408b
feat: ast to use new widget type void
linonetwo Aug 4, 2024
82ae767
test: add rule: 'parseBlock' and isRuleEnd: true
linonetwo Aug 4, 2024
893edf9
lint: quote
linonetwo Aug 4, 2024
d6b9d00
Update widget.js
linonetwo Aug 4, 2024
6ac9592
fix: void node need to handle its children
linonetwo Aug 4, 2024
9dbbcef
Update test-wikitext-parser.js
linonetwo Aug 4, 2024
e7d4819
lint: quote
linonetwo Aug 4, 2024
af2ddaa
Update void.js
linonetwo Aug 4, 2024
b8125d1
Update test-wikitext-parser.js
linonetwo Aug 4, 2024
2fa454a
fix: macrodef with comment (void node) not working
linonetwo Aug 7, 2024
fb8732a
lint: ' -> "
linonetwo Aug 7, 2024
078cd5f
feat: add to styleblock
linonetwo Aug 7, 2024
7c73f1f
feat: styleblock
linonetwo Aug 8, 2024
43f3f8b
feat: styleinline
linonetwo Aug 9, 2024
856cb42
Update table.js
linonetwo Aug 9, 2024
3cf93d0
lint: useless comments
linonetwo Aug 9, 2024
589241a
feat: transcludeblock
linonetwo Aug 9, 2024
0adf638
refactor: reuse block on inline when possible
linonetwo Aug 9, 2024
c4f6136
feat: use void node to carry important info for typedblock
linonetwo Aug 9, 2024
08e9312
feat: run all tests
linonetwo Aug 9, 2024
398d7f7
lint: useless ai generated comments
linonetwo Aug 10, 2024
6580536
Merge remote-tracking branch 'upstream/master' into feat/to-string
linonetwo Aug 10, 2024
f5fca2a
Update conditional.js to not include space
linonetwo Sep 4, 2024
043f60b
Update test-wikitext-serialize.js
linonetwo Sep 4, 2024
03798d7
Update conditional.js
linonetwo Sep 4, 2024
58507c0
refactor: move tiddlers to /data
linonetwo Sep 30, 2024
23489ce
refactor: no need for new $tw.Wiki()
linonetwo Sep 30, 2024
1a45520
lint: double quote
linonetwo Oct 2, 2024
4ea8ae4
Merge branch 'feat/to-string' of https://github.com/linonetwo/TiddlyW…
linonetwo Oct 2, 2024
1c50996
refactor: lowercase the parseblock rule name
linonetwo Oct 2, 2024
f0babe4
fix: Wiki parser initialize blockRuleClasses only when first new an i…
linonetwo Oct 12, 2024
375df47
feat: restore inline macro def
linonetwo Oct 12, 2024
53296a4
fix: macro in widget param
linonetwo Oct 13, 2024
72dd18d
fix: positional attribute in macro call
linonetwo Oct 13, 2024
fb9f7a5
fix: table space and horizrule block new line
linonetwo Oct 13, 2024
47cc03d
feat: make sure block rule all have \n\n for visiblity
linonetwo Oct 13, 2024
8056d8c
lint: function param
linonetwo Oct 13, 2024
0f38567
fix: empty list item
linonetwo Oct 13, 2024
f220dac
feat: add \n\n based on isBlock, if could also be inline
linonetwo Oct 13, 2024
5fdc9f3
fix: conditional without elseif
linonetwo Oct 13, 2024
87dc05b
refactor: use isBlock in macrodef to know inline or block
linonetwo Oct 14, 2024
2765e99
fix: link may not have attribute and children
linonetwo Feb 19, 2025
069181d
DEBUG: render result and diff below body only on browser
linonetwo Feb 19, 2025
86ec4ca
fix: remove pad space in />
linonetwo Feb 28, 2025
74c9841
test: remove pad space in />
linonetwo Feb 28, 2025
8ab1273
Revert DEBUG: render result and diff below body only on browser
linonetwo Mar 9, 2025
711bf01
refactor: fold commentText variable
linonetwo Mar 9, 2025
5c0198b
refactor: fold long comment
linonetwo Mar 9, 2025
a97aede
fix: double quotes for parameter values
linonetwo Mar 9, 2025
22749bb
Merge remote-tracking branch 'upstream/master' into feat/to-string
linonetwo Mar 22, 2025
7c6c0c3
Update void.js
linonetwo Mar 22, 2025
022b70d
Merge branch 'master' into feat/to-string
linonetwo Apr 28, 2025
1d3ec9b
refactor: move all exports.serialize = function(tree,serialize) { to …
linonetwo May 10, 2025
e07aca9
fix: expost listTypes from core, and require it in plugin
linonetwo May 10, 2025
8dac433
refactor: move serializeWikitextParseTree to plugin and init it
linonetwo May 10, 2025
2fea1c7
refactor: move serializeAttribute util also to the plugin
linonetwo May 14, 2025
f40a0ac
fix: Delete unused file
linonetwo May 14, 2025
5dc3e31
Merge branch 'master' into feat/to-string
linonetwo May 29, 2025
3da7564
Update macrodef.js
linonetwo May 29, 2025
0b40531
Update test-wikitext-parser.js
linonetwo May 29, 2025
a483074
Merge remote-tracking branch 'upstream/master' into feat/to-string
linonetwo Oct 11, 2025
79822f2
lint: fix
linonetwo Oct 11, 2025
a91fa06
Update plugins/tiddlywiki/wikitext-serialize/rules/filteredtransclude…
linonetwo Oct 11, 2025
82c2ad3
Update core/modules/widgets/void.js
linonetwo Oct 11, 2025
821e961
Update plugins/tiddlywiki/wikitext-serialize/rules/list.js
linonetwo Oct 11, 2025
c26564c
Update plugins/tiddlywiki/wikitext-serialize/rules/list.js
linonetwo Oct 11, 2025
163b8cf
Update plugins/tiddlywiki/wikitext-serialize/rules/styleblock.js
linonetwo Oct 11, 2025
e6d517b
Remove unused methods from VoidNodeWidget
linonetwo Oct 23, 2025
99ee212
docs: about regex in styleinline.js
linonetwo Oct 23, 2025
15c2a75
Merge remote-tracking branch 'upstream/master' into feat/to-string
linonetwo Oct 23, 2025
756d657
Update parsetree.js
linonetwo Oct 23, 2025
8cbd6c2
Update core/modules/widgets/void.js
linonetwo Oct 29, 2025
423973c
feat: Ensure at least one space after the style/class
linonetwo Oct 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions core/modules/parsers/wikiparser/rules/commentblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Note that the syntax for comments is simplified to an opening "<!--" sequence an
"use strict";

exports.name = "commentblock";
exports.types = {block:true, pragma:true};
exports.types = {block: true, pragma: true};

exports.init = function(parser) {
this.parser = parser;
Expand All @@ -43,9 +43,18 @@ exports.findNextMatch = function(startPos) {
return undefined;
};


exports.parse = function() {
// Move past the match
this.parser.pos = this.endMatchRegExp.lastIndex;
// Don't return any elements
return [];
// Return a node representing the comment that is not rendered
var commentStart = this.match.index;
var commentEnd = this.endMatch.index + this.endMatch[0].length;
return [{
type: "void",
children: [],
text: this.parser.source.slice(commentStart, commentEnd),
start: commentStart,
end: commentEnd
}];
};
11 changes: 9 additions & 2 deletions core/modules/parsers/wikiparser/rules/commentinline.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ exports.findNextMatch = function(startPos) {
exports.parse = function() {
// Move past the match
this.parser.pos = this.endMatchRegExp.lastIndex;
// Don't return any elements
return [];
// Return a node representing the inline comment
var commentStart = this.match.index;
var commentEnd = this.endMatch.index + this.endMatch[0].length;
return [{
type: "void",
text: this.parser.source.slice(commentStart, commentEnd),
start: commentStart,
end: commentEnd
}];
};
4 changes: 2 additions & 2 deletions core/modules/parsers/wikiparser/rules/extlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ exports.init = function(parser) {

exports.parse = function() {
// Move past the match
var start = this.parser.pos;
var start = this.parser.pos;
this.parser.pos = this.matchRegExp.lastIndex;
// Create the link unless it is suppressed
if(this.match[0].substr(0,1) === "~") {
return [{type: "text", text: this.match[0].substr(1)}];
return [{type: "text", text: this.match[0].substr(1), start: start, end: this.parser.pos}];
} else {
return [{
type: "element",
Expand Down
6 changes: 3 additions & 3 deletions core/modules/parsers/wikiparser/rules/fnprocdef.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ module-type: wikirule
Wiki pragma rule for function, procedure and widget definitions

```
\function name(param:defaultvalue,param2:defaultvalue)
\function name(param:"defaultvalue", param2:"defaultvalue")
definition text
\end

\procedure name(param:defaultvalue,param2:defaultvalue)
\procedure name(param:"defaultvalue", param2:"defaultvalue")
definition text
\end

\widget $mywidget(param:defaultvalue,param2:defaultvalue)
\widget $mywidget(param:"defaultvalue", param2:"defaultvalue")
definition text
\end
```
Expand Down
4 changes: 3 additions & 1 deletion core/modules/parsers/wikiparser/rules/hardlinebreaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ exports.parse = function() {
}
}
} while(match && !match[1]);
// Return the nodes
// Mark first and last node, and return the nodes
if(tree[0]) tree[0].isRuleStart = true;
if(tree[tree.length-1]) tree[tree.length-1].isRuleEnd = true;
return tree;
};
14 changes: 7 additions & 7 deletions core/modules/parsers/wikiparser/rules/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Parse the most recent match
exports.parse = function() {
// Retrieve the most recent match so that recursive calls don't overwrite it
var tag = this.nextTag;
if (!tag.isSelfClosing) {
if(!tag.isSelfClosing) {
tag.openTagStart = tag.start;
tag.openTagEnd = tag.end;
}
Expand All @@ -63,22 +63,22 @@ exports.parse = function() {
}
tag.end = this.parser.pos;
tag.closeTagEnd = tag.end;
if (tag.closeTagEnd === tag.openTagEnd || this.parser.source[tag.closeTagEnd - 1] !== '>') {
if(tag.closeTagEnd === tag.openTagEnd || this.parser.source[tag.closeTagEnd - 1] !== ">") {
tag.closeTagStart = tag.end;
} else {
tag.closeTagStart = tag.closeTagEnd - 2;
var closeTagMinPos = tag.children.length > 0 ? tag.children[tag.children.length-1].end : tag.openTagEnd;
if (!Number.isSafeInteger(closeTagMinPos)) closeTagMinPos = tag.openTagEnd;
while (tag.closeTagStart >= closeTagMinPos) {
if(!Number.isSafeInteger(closeTagMinPos)) closeTagMinPos = tag.openTagEnd;
while(tag.closeTagStart >= closeTagMinPos) {
var char = this.parser.source[tag.closeTagStart];
if (char === '>') {
if(char === ">") {
tag.closeTagStart = -1;
break;
}
if (char === '<') break;
if(char === "<") break;
tag.closeTagStart -= 1;
}
if (tag.closeTagStart < closeTagMinPos) {
if(tag.closeTagStart < closeTagMinPos) {
tag.closeTagStart = tag.end;
}
}
Expand Down
1 change: 1 addition & 0 deletions core/modules/parsers/wikiparser/rules/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var listTypes = {
":": {listTag: "dl", itemTag: "dd"},
">": {listTag: "blockquote", itemTag: "div"}
};
exports.listTypes = listTypes;

/*
Parse the most recent match
Expand Down
2 changes: 1 addition & 1 deletion core/modules/parsers/wikiparser/rules/macrocallblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports.findNextMatch = function(startPos) {
var c = this.parser.source.charAt(nextCall.end);
// Ensure EOL after parsed macro
// If we didn't need to support IE, we'd just use /(?:\r?\n|$)/ym
if ((c === "") || (c === "\n") || ((c === "\r") && this.parser.source.charAt(nextCall.end+1) === "\n")) {
if((c === "") || (c === "\n") || ((c === "\r") && this.parser.source.charAt(nextCall.end+1) === "\n")) {
this.nextCall = nextCall;
return nextStart;
}
Expand Down
2 changes: 2 additions & 0 deletions core/modules/parsers/wikiparser/rules/macrocallinline.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ exports.parse = function() {
this.parser.pos = call.end;
return [call];
};


6 changes: 4 additions & 2 deletions core/modules/parsers/wikiparser/rules/macrodef.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ exports.parse = function() {
}
}
// Is the remainder of the \define line blank after the parameter close paren?
var reEnd;
var reEnd,isBlock = true;
if(this.match[3]) {
// If so, it is a multiline definition and the end of the body is marked with \end
isBlock = false;
reEnd = new RegExp("((?:^|\\r?\\n)[^\\S\\n\\r]*\\\\end[^\\S\\n\\r]*(?:" + $tw.utils.escapeRegExp(this.match[1]) + ")?\\s*?(?:$|\\r?\\n))","mg");
} else {
// Otherwise, the end of the definition is marked by the end of the line
Expand All @@ -79,7 +80,8 @@ exports.parse = function() {
attributes: {},
children: [],
params: params,
isMacroDefinition: true
isMacroDefinition: true,
isBlock: isBlock && !!endMatch
}];
$tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"name",this.match[1]);
$tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"value",text);
Expand Down
10 changes: 8 additions & 2 deletions core/modules/parsers/wikiparser/rules/parsermode.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Parse the most recent match
*/
exports.parse = function() {
// Move past the pragma invocation
var start = this.parser.pos;
this.parser.pos = this.matchRegExp.lastIndex;
// Parse whitespace delimited tokens terminated by a line break
var reMatch = /[^\S\n]*(\S+)|(\r?\n)/mg,
Expand Down Expand Up @@ -58,6 +59,11 @@ exports.parse = function() {
this.parser.parseAsInline = true;
}
}
// No parse tree nodes to return
return [];
return [{
type: "void",
children: [],
parseAsInline: this.parser.parseAsInline,
start: start,
end: this.parser.pos
}];
};
2 changes: 2 additions & 0 deletions core/modules/parsers/wikiparser/rules/prettyextlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,5 @@ exports.parseLink = function(source,pos) {
node.end = closePos + 2;
return node;
};


2 changes: 1 addition & 1 deletion core/modules/parsers/wikiparser/rules/prettylink.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports.parse = function() {
var text = this.match[1],
link = this.match[2] || text,
textEndPos = this.parser.source.indexOf("|", start);
if (textEndPos < 0 || textEndPos > this.matchRegExp.lastIndex) {
if(textEndPos < 0 || textEndPos > this.matchRegExp.lastIndex) {
textEndPos = this.matchRegExp.lastIndex - 2;
}
var linkStart = this.match[2] ? (start + this.match[1].length + 1) : start;
Expand Down
11 changes: 9 additions & 2 deletions core/modules/parsers/wikiparser/rules/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ exports.parse = function() {
if(tokens.length > 0) {
this.parser.amendRules(tokens[0],tokens.slice(1));
}
// No parse tree nodes to return
return [];
// No widget to render, return void node.
return [{
type: "void",
attributes: {
action: {type: "string", value: tokens[0]},
rules: {type: "string", value: tokens.slice(1).join(" ")}
},
children: []
}];
};
5 changes: 4 additions & 1 deletion core/modules/parsers/wikiparser/rules/styleblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@ exports.parse = function() {
$tw.utils.addAttributeToParseTreeNode(tree[t],"style",styles.join(""));
}
}
return tree;
return [{
type: "void",
children: tree
}]
};
2 changes: 1 addition & 1 deletion core/modules/parsers/wikiparser/rules/styleinline.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exports.types = {inline: true};

exports.init = function(parser) {
this.parser = parser;
// Regexp to match
// Regexp to match /@@(styles)?\s*(\.class\s+)?/
this.matchRegExp = /@@((?:[^\.\r\n\s:]+:[^\r\n;]+;)+)?(\.(?:[^\r\n\s]+)\s+)?/mg;
};

Expand Down
33 changes: 24 additions & 9 deletions core/modules/parsers/wikiparser/rules/typedblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,37 @@ exports.parse = function() {
var parser = this.parser.wiki.parseText(parseType,text,{defaultType: "text/plain"});
// If there's no render type, just return the parse tree
if(!renderType) {
return parser.tree;
return [{
type: "void",
children: $tw.utils.isArray(parser.tree) ? parser.tree : [parser.tree],
parseType: parseType,
renderType: renderType,
text: text,
start: start,
end: this.parser.pos
}];
} else {
// Otherwise, render to the rendertype and return in a <PRE> tag
var widgetNode = this.parser.wiki.makeWidget(parser),
container = $tw.fakeDocument.createElement("div");
widgetNode.render(container,null);
text = renderType === "text/html" ? container.innerHTML : container.textContent;
var renderResult = renderType === "text/html" ? container.innerHTML : container.textContent;
// Use void node to carry important info for typedblock
return [{
type: "element",
tag: "pre",
type: "void",
children: [{
type: "text",
text: text,
start: start,
end: this.parser.pos
}]
type: "element",
tag: "pre",
children: [{
type: "text",
text: renderResult,
}]
}],
parseType: parseType,
renderType: renderType,
text: text,
start: start,
end: this.parser.pos
}];
}
};
24 changes: 12 additions & 12 deletions core/modules/parsers/wikiparser/wikiparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ WikiParser.prototype.parsePragmas = function() {
var subTree = nextMatch.rule.parse();
if(subTree.length > 0) {
// Set the start and end positions of the pragma rule if
if (subTree[0].start === undefined) subTree[0].start = start;
if (subTree[subTree.length - 1].end === undefined) subTree[subTree.length - 1].end = this.pos;
if(subTree[0].start === undefined) subTree[0].start = start;
if(subTree[subTree.length - 1].end === undefined) subTree[subTree.length - 1].end = this.pos;
$tw.utils.each(subTree, function (node) { node.rule = nextMatch.rule.name; });
// Quick hack; we only cope with a single parse tree node being returned, which is true at the moment
currentTreeBranch.push.apply(currentTreeBranch,subTree);
Expand Down Expand Up @@ -245,9 +245,9 @@ WikiParser.prototype.parseBlock = function(terminatorRegExpString) {
var start = this.pos;
var subTree = nextMatch.rule.parse();
// Set the start and end positions of the first and last blocks if they're not already set
if (subTree.length > 0) {
if (subTree[0].start === undefined) subTree[0].start = start;
if (subTree[subTree.length - 1].end === undefined) subTree[subTree.length - 1].end = this.pos;
if(subTree.length > 0) {
if(subTree[0].start === undefined) subTree[0].start = start;
if(subTree[subTree.length - 1].end === undefined) subTree[subTree.length - 1].end = this.pos;
}
$tw.utils.each(subTree, function (node) { node.rule = nextMatch.rule.name; });
return subTree;
Expand All @@ -256,7 +256,7 @@ WikiParser.prototype.parseBlock = function(terminatorRegExpString) {
var start = this.pos;
var children = this.parseInlineRun(terminatorRegExp);
var end = this.pos;
return [{type: "element", tag: "p", children: children, start: start, end: end }];
return [{type: "element", tag: "p", children: children, start: start, end: end, rule: "parseblock" }];
Comment thread
saqimtiaz marked this conversation as resolved.
};

/*
Expand Down Expand Up @@ -350,10 +350,10 @@ WikiParser.prototype.parseInlineRunUnterminated = function(options) {
var start = this.pos;
var subTree = nextMatch.rule.parse();
// Set the start and end positions of the first and last child if they're not already set
if (subTree.length > 0) {
if(subTree.length > 0) {
// Set the start and end positions of the first and last child if they're not already set
if (subTree[0].start === undefined) subTree[0].start = start;
if (subTree[subTree.length - 1].end === undefined) subTree[subTree.length - 1].end = this.pos;
if(subTree[0].start === undefined) subTree[0].start = start;
if(subTree[subTree.length - 1].end === undefined) subTree[subTree.length - 1].end = this.pos;
}
$tw.utils.each(subTree, function (node) { node.rule = nextMatch.rule.name; });
tree.push.apply(tree,subTree);
Expand Down Expand Up @@ -410,9 +410,9 @@ WikiParser.prototype.parseInlineRunTerminatedExtended = function(terminatorRegEx
var start = this.pos;
var subTree = inlineRuleMatch.rule.parse();
// Set the start and end positions of the first and last child if they're not already set
if (subTree.length > 0) {
if (subTree[0].start === undefined) subTree[0].start = start;
if (subTree[subTree.length - 1].end === undefined) subTree[subTree.length - 1].end = this.pos;
if(subTree.length > 0) {
if(subTree[0].start === undefined) subTree[0].start = start;
if(subTree[subTree.length - 1].end === undefined) subTree[subTree.length - 1].end = this.pos;
}
$tw.utils.each(subTree, function (node) { node.rule = inlineRuleMatch.rule.name; });
tree.push.apply(tree,subTree);
Expand Down
16 changes: 16 additions & 0 deletions core/modules/utils/parsetree.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,19 @@ exports.getParseTreeText = function getParseTreeText(tree) {
}
return output.join("");
};

exports.getParser = function(type,options) {
options = options || {};
// Select a parser
var Parser = $tw.Wiki.parsers[type];
if(!Parser && $tw.utils.getFileExtensionInfo(type)) {
Parser = $tw.Wiki.parsers[$tw.utils.getFileExtensionInfo(type).type];
}
if(!Parser) {
Parser = $tw.Wiki.parsers[options.defaultType || "text/vnd.tiddlywiki"];
}
if(!Parser) {
return null;
}
return Parser;
};
Comment thread
saqimtiaz marked this conversation as resolved.
7 changes: 4 additions & 3 deletions core/modules/widgets/importvariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
var parser = widgetPointer.wiki.parseTiddler(title,{parseAsInline:true, configTrimWhiteSpace:false});
if(parser) {
var parseTreeNode = parser.tree[0];
while(parseTreeNode && ["setvariable","set","parameters"].indexOf(parseTreeNode.type) !== -1) {
// process AST nodes generated by pragma rules.
while(parseTreeNode && ["setvariable","set","parameters","void"].indexOf(parseTreeNode.type) !== -1) {
var node = {
type: "set",
attributes: parseTreeNode.attributes,
Expand Down Expand Up @@ -82,7 +83,7 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
// this widget. If it needs to refresh,
// it'll do so along with the the whole
// importvariable tree.
if (widgetPointer != this) {
if(widgetPointer != this) {
widgetPointer.makeChildWidgets = function(){};
}
widgetPointer = widgetPointer.children[0];
Expand All @@ -93,7 +94,7 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
}
});

if (widgetPointer != this) {
if(widgetPointer != this) {
widgetPointer.parseTreeNode.children = this.parseTreeNode.children;
} else {
widgetPointer.makeChildWidgets();
Expand Down
Loading