1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-10-26 21:27:39 +00:00
João Bolila
2014-01-12 21:48:03 +00:00
parent 426f2978cf
commit c74bf6a655
3 changed files with 51 additions and 10 deletions

View File

@@ -14,15 +14,28 @@ Wraps up the fenced code blocks parser for highlight and use in TiddlyWiki5
var CodeBlockWidget = require("$:/core/modules/widgets/codeblock.js").codeblock;
CodeBlockWidget.prototype.postRender = function() {
var self = this,
lang = this.domNodes[0].getElementsByTagName('code')[0].className,
hljs = require("$:/plugins/tiddlywiki/highlight/highlight.js").hljs;
CodeBlockWidget.prototype.render = function(parent,nextSibling) {
var hljs, lang;
if($tw.browser && lang !== 'no-highlight') {
hljs.tabReplace = ' ';
hljs.highlightBlock(this.domNodes[0]);
}
this.parentDomNode = parent;
this.computeAttributes();
this.execute();
var codeNode = this.document.createElement("code");
if(this.getAttribute("language")) {
lang = this.getAttribute("language");
}
var domNode = this.document.createElement("pre");
codeNode.appendChild(this.document.createTextNode(this.getAttribute("code")));
domNode.appendChild(codeNode);
parent.insertBefore(domNode,nextSibling);
this.domNodes.push(domNode);
if($tw.browser && lang !== 'no-highlight') {
hljs = require("$:/plugins/tiddlywiki/highlight/highlight.js").hljs,
hljs.tabReplace = ' ';
hljs.highlightBlock(domNode);
}
};
})();