diff --git a/core/modules/utils/fakedom.js b/core/modules/utils/fakedom.js index 5175cebc5..05a500fa3 100755 --- a/core/modules/utils/fakedom.js +++ b/core/modules/utils/fakedom.js @@ -206,13 +206,29 @@ Object.defineProperty(TW_Element.prototype, "innerHTML", { set: function(value) { this.isRaw = true; this.rawHTML = value; + this.rawTextContent = null; + } +}); + +Object.defineProperty(TW_Element.prototype, "textInnerHTML", { + set: function(value) { + if(this.isRaw) { + this.rawTextContent = value; + } else { + throw "Cannot set textInnerHTML of a non-raw TW_Element"; + } } }); Object.defineProperty(TW_Element.prototype, "textContent", { get: function() { if(this.isRaw) { - throw "Cannot get textContent on a raw TW_Element"; + if(this.rawTextContent === null) { + console.log(booboo) + throw "Cannot get textContent on a raw TW_Element"; + } else { + return this.rawTextContent; + } } else { var b = []; $tw.utils.each(this.children,function(node) { diff --git a/plugins/tiddlywiki/highlight/highlightblock.js b/plugins/tiddlywiki/highlight/highlightblock.js index 80bd93fbb..e5049936b 100644 --- a/plugins/tiddlywiki/highlight/highlightblock.js +++ b/plugins/tiddlywiki/highlight/highlightblock.js @@ -28,12 +28,16 @@ CodeBlockWidget.prototype.postRender = function() { language = tiddler.fields.text || ""; } if(language) { - try { - domNode.className = language.toLowerCase() + " hljs"; - 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 + domNode.className = language.toLowerCase() + " hljs"; + if($tw.browser && !domNode.isTiddlyWikiFakeDom) { + hljs.highlightBlock(domNode); + } else { + var text = domNode.textContent; + domNode.children[0].innerHTML = hljs.fixMarkup(hljs.highlight(language,text).value); + // If we're using the fakedom then specially save the original raw text + if(domNode.isTiddlyWikiFakeDom) { + domNode.children[0].textInnerHTML = text; + } } } };