From ec1ec8ccd8942adb33f6aa148219bc7759c0bca7 Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Sat, 21 May 2022 16:31:34 +0100 Subject: [PATCH] Fix invocation of JS macros --- core/modules/widgets/transclude.js | 4 ++-- core/modules/widgets/widget.js | 3 ++- .../tests/data/transclude/JavaScript-Macro.tid | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 editions/test/tiddlers/tests/data/transclude/JavaScript-Macro.tid diff --git a/core/modules/widgets/transclude.js b/core/modules/widgets/transclude.js index 38970efb9..c113c1861 100755 --- a/core/modules/widgets/transclude.js +++ b/core/modules/widgets/transclude.js @@ -200,8 +200,8 @@ TranscludeWidget.prototype.getTransclusionTarget = function() { $tw.utils.each(srcVariable.params,function(param) { $tw.utils.addAttributeToParseTreeNode(parser.tree[0],param.name,param["default"]) }); - } else if(srcVariable.isMacroDefinition) { - // For macros, wrap the parse tree in a vars widget assigning the parameters to variables named "__paramname__" + } else { + // For macros and ordinary variables, wrap the parse tree in a vars widget assigning the parameters to variables named "__paramname__" parser = { tree: [ { diff --git a/core/modules/widgets/widget.js b/core/modules/widgets/widget.js index 9fcda8e51..18b395ec0 100755 --- a/core/modules/widgets/widget.js +++ b/core/modules/widgets/widget.js @@ -148,7 +148,8 @@ Widget.prototype.getVariableInfo = function(name,options) { } // If the variable doesn't exist in the parent widget then look for a macro module return { - text: this.evaluateMacroModule(name,actualParams,options.defaultValue) + text: this.evaluateMacroModule(name,actualParams,options.defaultValue), + srcVariable: {} }; }; diff --git a/editions/test/tiddlers/tests/data/transclude/JavaScript-Macro.tid b/editions/test/tiddlers/tests/data/transclude/JavaScript-Macro.tid new file mode 100644 index 000000000..216a89dc8 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/JavaScript-Macro.tid @@ -0,0 +1,17 @@ +title: Transclude/Macro/JavaScript +description: Transcluding a javascript macro +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim + +<> + +<$macrocall $name="makedatauri" text="Wildebeest" type="text/plain"/> + ++ +title: ExpectedResult + +

data:text/plain,Wildebeest

data:text/plain,Wildebeest

\ No newline at end of file