TiddlyWiki5/plugins/tiddlywiki/highlight/highlightblock.js

31 wiersze
755 B
JavaScript

/*\
title: $:/plugins/tiddlywiki/highlight/highlightblock.js
type: application/javascript
module-type: widget
Wraps up the fenced code blocks parser for highlight and use in TiddlyWiki5
\*/
(function() {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var CodeBlockWidget = require("$:/core/modules/widgets/codeblock.js").codeblock;
if($tw.browser) {
var hljs = require("$:/plugins/tiddlywiki/highlight/highlight.js").hljs;
hljs.configure({tabReplace: " "});
}
CodeBlockWidget.prototype.postRender = function() {
var domNode = this.domNodes[0];
if($tw.browser && this.document !== $tw.fakeDocument && this.language) {
domNode.className = this.language.toLowerCase();
hljs.highlightBlock(domNode);
}
};
})();