Hi everyone!
I wanted Lua code in my wiki to get proper treatment, so I whipped up a little hack to make adding new languages/brushes a cinch. I've seen people ask about this in the past, so I thought I'd share the code I wrote.
Here's the JS code that does the magic:
exports.after = ['load-modules'];
exports.startup = function startup() {
let hljs = $tw.modules.execute('$:/plugins/tiddlywiki/highlight/highlight.js');
$tw.modules.forEachModuleOfType('highlighter', function(title, module) {
let moduleSource = $tw.wiki.getTiddlerText(title);
$tw.utils.evalSandboxed(moduleSource, {hljs:hljs, exports:{}}, title);
});
};
Put this in a tiddler - you can name it whatever you want, but its "type" field needs to be "application/javascript", and it needs its "module-type" field set to "startup". Once you add this and reload your wiki, this code will look for highlight.js brushes in tiddlers that have a module-type of "highlighter" and load them for use in highlighting.
For example, I grabbed the Lua highlighter source from
https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.8.0/languages/lua.min.js, put it in a tiddler with "module-type: highlighter", reloaded my wiki, and viola - highlighted Lua code. I recommend always grabbing the 8.8.0 version of any language you add, since that's the version of highlight.js that TiddlyWiki includes with the plugin.
-Rob