mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-27 10:30:28 +00:00
5d3dda1a17
The current implementation of the highlight plugin only works properly in the browser, and doesn’t work under Node.js. It also doesn’t work when rendering to the fakedom in the browser (as happens when rendering stylesheets, for example).
42 lines
1.1 KiB
JavaScript
42 lines
1.1 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;
|
|
|
|
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);
|
|
}
|
|
};
|
|
|
|
})();
|