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
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/2a1fb397-1a9b-4db5-aa9e-087dc8bccceb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.