1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-01 17:53:15 +00:00
TiddlyWiki5/plugins/tiddlywiki/highlight/highlightblock.js
James Welford Anderson cc85368fd4 highlightjs in nodejs
2015-01-03 02:00:08 +09:00

38 lines
1.0 KiB
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;
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);
}
else if(!$tw.browser && this.language && this.language.indexOf("/") == -1 ){
try{
domNode.className = this.language.toLowerCase() + " hljs";
domNode.children[0].innerHTML = hljs.fixMarkup(hljs.highlight(this.language, this.getAttribute("code")).value);
}
catch(err) {
//alert(err);
}
}
};
})();