1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-09-11 23:36:05 +00:00

Clean up the highlight plugin

Fixing various issues that were preventing language specifiers from
working.
This commit is contained in:
Jermolene
2014-02-10 13:51:38 +00:00
parent e003889171
commit ecba4f71ea
4 changed files with 32 additions and 50 deletions

View File

@@ -8,34 +8,20 @@ Wraps up the fenced code blocks parser for highlight and use in TiddlyWiki5
\*/
(function() {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var CodeBlockWidget = require("$:/core/modules/widgets/codeblock.js").codeblock;
var CodeBlockWidget = require("$:/core/modules/widgets/codeblock.js").codeblock;
CodeBlockWidget.prototype.render = function(parent,nextSibling) {
var hljs, lang;
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 && this.document !== $tw.fakeDocument && lang !== 'no-highlight') {
hljs = require("$:/plugins/tiddlywiki/highlight/highlight.js").hljs,
hljs.tabReplace = ' ';
hljs.highlightBlock(domNode);
}
};
CodeBlockWidget.prototype.postRender = function() {
var domNode = this.domNodes[0];
if($tw.browser && this.document !== $tw.fakeDocument && this.language) {
domNode.className = this.language;
var hljs = require("$:/plugins/tiddlywiki/highlight/highlight.js").hljs;
hljs.tabReplace = " ";
hljs.highlightBlock(domNode);
}
};
})();