From cbe2a53d6a8bbd22f53d88a3b8e7fde2f3f05630 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Mon, 6 Oct 2014 21:10:35 +0100 Subject: [PATCH] Extend fakedom for KaTeX on Node.js To make KaTeX work on the server we need to add support for the style attribute and for setting the textContent of an element. --- core/modules/utils/fakedom.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/modules/utils/fakedom.js b/core/modules/utils/fakedom.js index dd36369a2..d7cb633b7 100755 --- a/core/modules/utils/fakedom.js +++ b/core/modules/utils/fakedom.js @@ -39,6 +39,7 @@ var TW_Element = function(tag,namespace) { this.attributes = {}; this.isRaw = false; this.children = []; + this.style = {}; this.namespaceURI = namespace || "http://www.w3.org/1999/xhtml"; }; @@ -137,6 +138,13 @@ Object.defineProperty(TW_Element.prototype, "outerHTML", { } } } + if(this.style) { + var style = []; + for(var s in this.style) { + style.push(s + ":" + this.style[s] + ";"); + } + output.push(" style='",style.join(""),"'") + } output.push(">"); if($tw.config.htmlVoidElements.indexOf(this.tag) === -1) { output.push(this.innerHTML); @@ -179,6 +187,9 @@ Object.defineProperty(TW_Element.prototype, "textContent", { }); return b.join(""); } + }, + set: function(value) { + this.children = [new TW_TextNode(value)]; } });