diff --git a/core/modules/filterrunprefixes/let.js b/core/modules/filterrunprefixes/let.js index 8f877b18c..d8afdd1a1 100644 --- a/core/modules/filterrunprefixes/let.js +++ b/core/modules/filterrunprefixes/let.js @@ -16,27 +16,27 @@ Assign a value to a variable Export our filter prefix function */ exports.let = function(operationSubFunction,options) { - if(options.suffixes[0] && options.suffixes[0][0]) { - // Save the variable name - var name = options.suffixes[0][0]; - // Return the filter run prefix function - return function(results,source,widget) { - // Set the input source to the incoming results - var inputSource = widget.wiki.makeTiddlerIterator(results.toArray()); - // Assign the result of the subfunction to the variable - var variables = {}; - variables[name] = operationSubFunction(inputSource,widget); - // Clear the results - results.clear(); - // Return the variables - return { - variables: variables - }; + // Return the filter run prefix function + return function(results,source,widget) { + // Evaluate the subfunction to get the variable name + var subFunctionResults = operationSubFunction(source,widget); + if(subFunctionResults.length === 0) { + return; + } + var name = subFunctionResults[0]; + if(typeof name !== "string" || name.length === 0) { + return; + } + // Assign the result of the subfunction to the variable + var variables = {}; + variables[name] = results.toArray() + // Clear the results + results.clear(); + // Return the variables + return { + variables: variables }; - } else { - // Return nothing if there is no variable name - return function(results,source,widget) {}; - } + }; }; })(); diff --git a/editions/test/tiddlers/tests/data/let-filter-prefix/ResultList.tid b/editions/test/tiddlers/tests/data/let-filter-prefix/ResultList.tid index ee9e8e800..4263e565b 100644 --- a/editions/test/tiddlers/tests/data/let-filter-prefix/ResultList.tid +++ b/editions/test/tiddlers/tests/data/let-filter-prefix/ResultList.tid @@ -5,7 +5,7 @@ tags: [[$:/tags/wiki-test-spec]] title: Output -<$text text={{{ :let:varname[all[tiddlers]] [varlist[varname]sort[]join[,]] }}}/> +<$text text={{{ [all[tiddlers]] :let[[varname]] [varlist[varname]sort[]join[,]] }}}/> + title: ExpectedResult diff --git a/editions/test/tiddlers/tests/data/let-filter-prefix/Simple.tid b/editions/test/tiddlers/tests/data/let-filter-prefix/Simple.tid index 6385c83e2..f16ea107f 100644 --- a/editions/test/tiddlers/tests/data/let-filter-prefix/Simple.tid +++ b/editions/test/tiddlers/tests/data/let-filter-prefix/Simple.tid @@ -5,7 +5,7 @@ tags: [[$:/tags/wiki-test-spec]] title: Output -<$text text={{{ :let:varname[[magpie]] [] +[join[-]] }}}/> +<$text text={{{ [[magpie]] :let[[varname]] [] +[join[-]] }}}/> + title: ExpectedResult diff --git a/editions/test/tiddlers/tests/data/let-filter-prefix/UseInput.tid b/editions/test/tiddlers/tests/data/let-filter-prefix/UseInput.tid index c20e16442..4d0aa8eba 100644 --- a/editions/test/tiddlers/tests/data/let-filter-prefix/UseInput.tid +++ b/editions/test/tiddlers/tests/data/let-filter-prefix/UseInput.tid @@ -5,7 +5,7 @@ tags: [[$:/tags/wiki-test-spec]] title: Output -<$text text={{{ [[colossus]] :let:another[all[]] [] +[join[-]] }}}/> +<$text text={{{ [[colossus]] :let[[another]] [] +[join[-]] }}}/> + title: ExpectedResult diff --git a/editions/tw5.com/tiddlers/filters/syntax/Let Filter Run Prefix.tid b/editions/tw5.com/tiddlers/filters/syntax/Let Filter Run Prefix.tid index 28762875f..8d4ed15a4 100644 --- a/editions/tw5.com/tiddlers/filters/syntax/Let Filter Run Prefix.tid +++ b/editions/tw5.com/tiddlers/filters/syntax/Let Filter Run Prefix.tid @@ -3,7 +3,7 @@ from-version: 5.3.7 modified: 20250307212252946 rp-input: all titles from previous filter runs rp-output: an empty title list is always returned from the "let" filter run prefix -rp-purpose: assign the results of a filter run to a variable +rp-purpose: assign the title list resulting from previous filter runs to a multi-valued variable tags: [[Named Filter Run Prefix]] title: Let Filter Run Prefix type: text/vnd.tiddlywiki @@ -11,14 +11,13 @@ type: text/vnd.tiddlywiki <$railroad text=""" \start none \end none -( ":let" ) -( ":" ) -( : "variable" ) -( ":" ) +( ":let" ) [[run|"Filter Run"]] """/> -<<.from-version "5.3.7">> The `:let` filter run prefix assigns the result list of a filter run to a variable which is made available to the remaining [[filter runs|Filter Run]] in the [[filter expression|Filter Expression]]. Only the first item in the result list is returned when the variable is accessed in the usual way (or an empty string if the result list is empty). The special [varlist Operator] is used to access all the items in the result list. +The `:let` filter run prefix assigns the title list resulting from previous filter runs to a [[multi-valued variable|Multi-Valued Variable]]. The variable is named with the first result returned by the filter run. + +The variable is made available to the remaining [[filter runs|Filter Run]] in the [[filter expression|Filter Expression]]. Only the first item in the result list is returned when the variable is accessed in the usual way (or an empty string if the result list is empty). The special [varlist Operator] is used to access all the items in the result list. Within the filter run the [[all Operator]] with an empty parameter retrieves all the titles from the previous filter runs, instead of the usual behaviour of retieving all the titles that were passed to the filter expression.