2014-01-05 09:58:01 +00:00
|
|
|
/*\
|
|
|
|
title: $:/plugins/tiddlywiki/highlight/highlightblock.js
|
|
|
|
type: application/javascript
|
2014-01-07 22:57:46 +00:00
|
|
|
module-type: widget
|
2014-01-05 09:58:01 +00:00
|
|
|
|
|
|
|
Wraps up the fenced code blocks parser for highlight and use in TiddlyWiki5
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function() {
|
|
|
|
|
2014-01-07 22:57:46 +00:00
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
2014-01-05 09:58:01 +00:00
|
|
|
|
2014-01-07 22:57:46 +00:00
|
|
|
var CodeBlockWidget = require("$:/core/modules/widgets/codeblock.js").codeblock;
|
2014-01-05 09:58:01 +00:00
|
|
|
|
2014-01-12 21:48:03 +00:00
|
|
|
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 && lang !== 'no-highlight') {
|
|
|
|
hljs = require("$:/plugins/tiddlywiki/highlight/highlight.js").hljs,
|
|
|
|
hljs.tabReplace = ' ';
|
|
|
|
hljs.highlightBlock(domNode);
|
|
|
|
}
|
2014-01-07 22:57:46 +00:00
|
|
|
};
|
2014-01-05 09:58:01 +00:00
|
|
|
|
|
|
|
})();
|