diff --git a/core/modules/macros/tiddler.js b/core/modules/macros/tiddler.js index 4d0b4ee74..cff3597cf 100644 --- a/core/modules/macros/tiddler.js +++ b/core/modules/macros/tiddler.js @@ -51,6 +51,7 @@ exports.info = { params: { target: {byName: "default", type: "tiddler"}, template: {byName: true, type: "tiddler"}, + templateText: {byName: true, type: "text"}, "with": {byName: true, type: "text", dependentAll: true} } }; @@ -70,75 +71,73 @@ exports.evaluateDependencies = function() { }; exports.executeMacro = function() { - var renderTitle = this.params.target, - renderTemplate = this.params.template, - children, - childrenClone = [], + var renderTitle, renderTemplateTitle, renderTemplateTree, + children, parseTree, t, parents = this.parents.slice(0), parseOptions = {}; // If there's no render title specified then use the current tiddler title - if(typeof renderTitle !== "string") { + if(this.hasParameter("target")) { + renderTitle = this.params.target; + } else { renderTitle = this.tiddlerTitle; } - // If there's no template specified then use the target tiddler title - if(typeof renderTemplate !== "string") { - renderTemplate = renderTitle; - } - // Check for recursion - if(parents.indexOf(renderTemplate) !== -1) { - children = [$tw.Tree.errorNode("Tiddler recursion error in <> macro")]; + // Get the render tree for the template + if(this.hasParameter("templateText")) { + renderTemplateTree = this.wiki.parseText("text/x-tiddlywiki",this.params.templateText).tree; } else { - // Check for substitution parameters - if(this.hasParameter("with")) { - parseOptions["with"] = [undefined,this.params["with"]]; // TODO: Allow for more than one with: parameter + if(this.hasParameter("template")) { + renderTemplateTitle = this.params.template; + } else { + renderTemplateTitle = renderTitle; + } + // Check for recursion + if(parents.indexOf(this.params.templateTitle) !== -1) { + renderTemplateTree = $tw.Tree.errorNode("Tiddler recursion error in <> macro"); + } else { + parents.push(renderTemplateTitle); + renderTemplateTree = []; + // Check for substitution parameters + if(this.hasParameter("with")) { + parseOptions["with"] = [undefined,this.params["with"]]; // TODO: Allow for more than one with: parameter + } + parseTree = this.wiki.parseTiddler(renderTemplateTitle,parseOptions); + children = parseTree ? parseTree.tree : []; + for(t=0; t