mirror of
https://github.com/TiddlyWiki/TiddlyWiki5.git
synced 2026-04-25 05:44:38 +00:00
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:
27
core/modules/filters/macro.js
Normal file
27
core/modules/filters/macro.js
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user