From cc85368fd48f1e5878018a4e00b6c17d436e67a9 Mon Sep 17 00:00:00 2001 From: James Welford Anderson Date: Sat, 3 Jan 2015 02:00:08 +0900 Subject: [PATCH] highlightjs in nodejs --- .../tiddlywiki/highlight/files/tiddlywiki.files | 4 ++-- plugins/tiddlywiki/highlight/highlightblock.js | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/plugins/tiddlywiki/highlight/files/tiddlywiki.files b/plugins/tiddlywiki/highlight/files/tiddlywiki.files index 716dc8cc3..36dce3c80 100644 --- a/plugins/tiddlywiki/highlight/files/tiddlywiki.files +++ b/plugins/tiddlywiki/highlight/files/tiddlywiki.files @@ -7,8 +7,8 @@ "title": "$:/plugins/tiddlywiki/highlight/highlight.js", "module-type": "library" }, - "prefix": "var hljs;if($tw.browser){\n", - "suffix": "}\nexports.hljs = hljs;\n" + "prefix": "var hljs;\n", + "suffix": "\nexports.hljs = hljs;\n" }, { "file": "default.css", diff --git a/plugins/tiddlywiki/highlight/highlightblock.js b/plugins/tiddlywiki/highlight/highlightblock.js index 8761b0e3f..ab3e706dd 100644 --- a/plugins/tiddlywiki/highlight/highlightblock.js +++ b/plugins/tiddlywiki/highlight/highlightblock.js @@ -14,10 +14,8 @@ Wraps up the fenced code blocks parser for highlight and use in TiddlyWiki5 var CodeBlockWidget = require("$:/core/modules/widgets/codeblock.js").codeblock; -if($tw.browser) { - var hljs = require("$:/plugins/tiddlywiki/highlight/highlight.js").hljs; - hljs.configure({tabReplace: " "}); -} +var hljs = require("$:/plugins/tiddlywiki/highlight/highlight.js").hljs; +hljs.configure({tabReplace: " "}); CodeBlockWidget.prototype.postRender = function() { var domNode = this.domNodes[0]; @@ -25,6 +23,15 @@ CodeBlockWidget.prototype.postRender = function() { domNode.className = this.language.toLowerCase(); hljs.highlightBlock(domNode); } + else if(!$tw.browser && this.language && this.language.indexOf("/") == -1 ){ + try{ + domNode.className = this.language.toLowerCase() + " hljs"; + domNode.children[0].innerHTML = hljs.fixMarkup(hljs.highlight(this.language, this.getAttribute("code")).value); + } + catch(err) { + //alert(err); + } + } }; })();