From 4be5f0abe8830de7e11138d56aaa3aba420ed615 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Wed, 28 Sep 2016 11:34:15 +0100 Subject: [PATCH] Switch highlight plugin under Node.js to use DOM rather than raw HTML MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi @welford I wondered if you could kindly review this commit, since you authored the original code? Before this commit, I was running into a crash when running `prerelease-bld.sh` from `build.jermolene.github.io`, caused by using raw HTML for the highlighted block. Switching to the fake dom seems to fix things, but I’d like a second pair of eyes. --- plugins/tiddlywiki/highlight/highlightblock.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/plugins/tiddlywiki/highlight/highlightblock.js b/plugins/tiddlywiki/highlight/highlightblock.js index e89251c7f..80bd93fbb 100644 --- a/plugins/tiddlywiki/highlight/highlightblock.js +++ b/plugins/tiddlywiki/highlight/highlightblock.js @@ -27,15 +27,11 @@ CodeBlockWidget.prototype.postRender = function() { if(tiddler) { language = tiddler.fields.text || ""; } - if($tw.browser && this.document !== $tw.fakeDocument && language) { - domNode.className = language.toLowerCase(); - hljs.highlightBlock(domNode); - } else if(!$tw.browser && language && language.indexOf("/") === -1 ){ + if(language) { try { domNode.className = language.toLowerCase() + " hljs"; - domNode.children[0].innerHTML = hljs.fixMarkup(hljs.highlight(language, this.getAttribute("code")).value); - } - catch(err) { + hljs.highlightBlock(domNode); + } catch(err) { // Can't easily tell if a language is registered or not in the packed version of hightlight.js, // so we silently fail and the codeblock remains unchanged }