diff --git a/core/modules/filters/getvariablejson.js b/core/modules/filters/getvariablejson.js new file mode 100644 index 000000000..32b665461 --- /dev/null +++ b/core/modules/filters/getvariablejson.js @@ -0,0 +1,31 @@ +/*\ +title: $:/core/modules/filters/getvariablejson.js +type: application/javascript +module-type: filteroperator + +Filter operator for replacing input values by the value of the variable with the same name, or blank if the variable is missing + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Export our filter function +*/ +exports.getvariablejson = function(source,operator,options) { + var results = [], + space = operator.operands[1] || null, + replacerList = (operator.operands[2]) ? operator.operands[2].split(" ") : null, + widget = options.widget; + source(function(tiddler,title) { + var variable = widget.getVariableInfo(title, {}), + text = JSON.stringify(variable,replacerList,space); + results.push(text || ""); + }); + return results; +}; + +})(); diff --git a/editions/tw5.com/tiddlers/test-getvariablejson.tid b/editions/tw5.com/tiddlers/test-getvariablejson.tid new file mode 100644 index 000000000..d532733e0 --- /dev/null +++ b/editions/tw5.com/tiddlers/test-getvariablejson.tid @@ -0,0 +1,27 @@ +created: 20240506064659892 +modified: 20240506100851338 +tags: +title: test-getvariablejson +type: text/vnd.tiddlywiki + +\define test-macro(a:10) test macro + +\procedure test-proc(a:10) test proc + +\function my.test(x:3, abc:def) [split[ ]] + + +\define elements() srcVariable params name default +\define openBracket() [ +\define closeBracket() ] + + +<<.example 1 """\procedure test-proc(a:10) test proc +\function my.test(x:3, abc:def) [split[ ]] +\function tab() [charcode[9]] + +
<$text text={{{[[my.test]getvariablejson[],]}}}/>
+""">> + +<<.example 2 """
<$text text={{{[[my.test]getvariablejson[],] +[jsonextract[srcVariable],[params]] +[format:json]  }}}/>
""">> +