Add macro operator (#9520)

* Add macro operator

* Replace unnecessary usage of wikify widget

* Simplify multiple let widget

* fixup! Replace unnecessary usage of wikify widget

* Update tests

* Update change note

* fixup! Replace unnecessary usage of wikify widget

* Update docs

* fixup! Update tests
This commit is contained in:
XLBilly
2026-01-04 19:31:30 +08:00
committed by GitHub
parent 921c0174fb
commit 3c8ee86e23
9 changed files with 80 additions and 31 deletions

View File

@@ -0,0 +1,27 @@
/*\
title: $:/core/modules/filters/macro.js
type: application/javascript
module-type: filteroperator
Filter operator returning those input titles that are returned from a javascript macro
\*/
"use strict";
/*
Export our filter function
*/
exports.macro = function(source,operator,options) {
const macroName = operator.operands[0],
results = [];
if($tw.macros[macroName] !== undefined) {
results.push($tw.macros[macroName].run(...operator.operands.slice(1)));
} else {
// Return the input list if the macro wasn't found
source((tiddler,title) => {
results.push(title);
});
}
return results;
};