Macros can be implemented as JavaScript modules as well as via the wikitext syntax.
JavaScript macros are modules with their module-type field set to macro. They must export these three properties:
this
points to the widget node invoking the macro.Note that if the params array is missing or blank, then all the supplied parameters are passed to the run()
method.
There are several JavaScript macros built into the core which can serve as a jumping off point for your own macros:
https://github.com/Jermolene/TiddlyWiki5/tree/master/core/modules/macros
Note that JavaScript macros work on both the client and the server, and so do not have access to the browser DOM.
Macros are just used to return a chunk of wikitext for further processing. They should not make modifications to tiddlers in the wiki store. The reason is that you cannott control when the macro is called; it may be called repeatedly as part of refresh processing. So it is important that macros do not have any other side effects beyond generating their text.