mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-10-02 17:00:45 +00:00
Change tiddler macro to use parseTiddler parameter substitution
This commit is contained in:
parent
52a51b79aa
commit
44bef260f0
@ -75,7 +75,8 @@ exports.executeMacro = function() {
|
|||||||
children,
|
children,
|
||||||
childrenClone = [],
|
childrenClone = [],
|
||||||
t,
|
t,
|
||||||
parents = this.parents.slice(0);
|
parents = this.parents.slice(0),
|
||||||
|
parseOptions = {};
|
||||||
// If there's no render title specified then use the current tiddler title
|
// If there's no render title specified then use the current tiddler title
|
||||||
if(typeof renderTitle !== "string") {
|
if(typeof renderTitle !== "string") {
|
||||||
renderTitle = this.tiddlerTitle;
|
renderTitle = this.tiddlerTitle;
|
||||||
@ -88,22 +89,14 @@ exports.executeMacro = function() {
|
|||||||
if(parents.indexOf(renderTemplate) !== -1) {
|
if(parents.indexOf(renderTemplate) !== -1) {
|
||||||
children = [$tw.Tree.errorNode("Tiddler recursion error in <<tiddler>> macro")];
|
children = [$tw.Tree.errorNode("Tiddler recursion error in <<tiddler>> macro")];
|
||||||
} else {
|
} else {
|
||||||
|
// Check for substitution parameters
|
||||||
if(this.hasParameter("with")) {
|
if(this.hasParameter("with")) {
|
||||||
// Parameterised transclusion
|
parseOptions["with"] = [undefined,this.params["with"]]; // TODO: Allow for more than one with: parameter
|
||||||
var targetTiddler = this.wiki.getTiddler(renderTemplate),
|
|
||||||
text = targetTiddler.fields.text;
|
|
||||||
var withTokens = [this.params["with"]]; // TODO: Allow for more than one with: parameter
|
|
||||||
for(t=0; t<withTokens.length; t++) {
|
|
||||||
var placeholderRegExp = new RegExp("\\$"+(t+1),"mg");
|
|
||||||
text = text.replace(placeholderRegExp,withTokens[t]);
|
|
||||||
}
|
}
|
||||||
children = this.wiki.parseText(targetTiddler.fields.type,text).tree;
|
// Render the target tiddler
|
||||||
} else {
|
var parseTree = this.wiki.parseTiddler(renderTemplate,parseOptions);
|
||||||
// There's no parameterisation, so we can just render the target tiddler directly
|
|
||||||
var parseTree = this.wiki.parseTiddler(renderTemplate);
|
|
||||||
children = parseTree ? parseTree.tree : [];
|
children = parseTree ? parseTree.tree : [];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Update the stack of tiddler titles for recursion detection
|
// Update the stack of tiddler titles for recursion detection
|
||||||
parents.push(renderTemplate);
|
parents.push(renderTemplate);
|
||||||
// Clone the children
|
// Clone the children
|
||||||
|
Loading…
Reference in New Issue
Block a user