mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-10-26 21:27:39 +00:00
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user