diff --git a/core/modules/new_widgets/macrocall.js b/core/modules/new_widgets/macrocall.js index 5b13197d8..f100f4059 100644 --- a/core/modules/new_widgets/macrocall.js +++ b/core/modules/new_widgets/macrocall.js @@ -37,19 +37,30 @@ MacroCallWidget.prototype.render = function(parent,nextSibling) { Compute the internal state of the widget */ MacroCallWidget.prototype.execute = function() { + // Get the parse type if specified + this.parseType = this.getAttribute("$type","text/vnd.tiddlywiki"); + this.renderOutput = this.getAttribute("$output","text/html"); // Merge together the parameters specified in the parse tree with the specified attributes var params = this.parseTreeNode.params ? this.parseTreeNode.params.slice(0) : []; $tw.utils.each(this.attributes,function(attribute,name) { - if(name !== "$name") { + if(name.charAt(0) !== "$") { params.push({name: name, value: attribute}); } }); // Get the macro value - var text = this.getVariable(this.parseTreeNode.name || this.getAttribute("$name"),{params: params}); - // Parse the macro - var parser = this.wiki.new_parseText("text/vnd.tiddlywiki",text, - {parseAsInline: !this.parseTreeNode.isBlock}), + var text = this.getVariable(this.parseTreeNode.name || this.getAttribute("$name"),{params: params}), + parseTreeNodes; + // Are we rendering to HTML? + if(this.renderOutput === "text/html") { + // If so we'll return the parsed macro + var parser = this.wiki.new_parseText(this.parseType,text, + {parseAsInline: !this.parseTreeNode.isBlock}); parseTreeNodes = parser ? parser.tree : []; + } else { + // Otherwise, we'll render the text + var plainText = this.wiki.new_renderText("text/plain",this.parseType,text,{parentWidget: this}); + parseTreeNodes = [{type: "text", text: plainText}]; + } // Construct the child widgets this.makeChildWidgets(parseTreeNodes); }; diff --git a/editions/tw5.com/tiddlers/widgets/MacroCallWidget.tid b/editions/tw5.com/tiddlers/widgets/MacroCallWidget.tid index e991c6c3c..1d61f34f2 100644 --- a/editions/tw5.com/tiddlers/widgets/MacroCallWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/MacroCallWidget.tid @@ -31,4 +31,6 @@ The content of the `<$macrocall>` widget is ignored. |!Attribute |!Description | |$name |Name of the macro to invoke | +|$type |ContentType with which the macro text should be parsed (defaults to `text/vnd.tiddlywiki`) | +|$output |ContentType for the output rendering (defaults to `text/html`, can also be `text/plain`) | |//parameters// |Macro parameters specified as attributes |