1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Update KaTeX wrapper to support operation under Node.js

Now we can generate static HTML containing mathematical typesetting
This commit is contained in:
Jermolene 2014-10-06 21:20:19 +01:00
parent cbe2a53d6a
commit 63c174d7ed
5 changed files with 18 additions and 7 deletions

View File

@ -143,7 +143,9 @@ Object.defineProperty(TW_Element.prototype, "outerHTML", {
for(var s in this.style) { for(var s in this.style) {
style.push(s + ":" + this.style[s] + ";"); style.push(s + ":" + this.style[s] + ";");
} }
output.push(" style='",style.join(""),"'") if(style.length > 0) {
output.push(" style='",style.join(""),"'")
}
} }
output.push(">"); output.push(">");
if($tw.config.htmlVoidElements.indexOf(this.tag) === -1) { if($tw.config.htmlVoidElements.indexOf(this.tag) === -1) {

View File

@ -2,9 +2,7 @@ title: HelloThere
This is a TiddlyWiki plugin for mathematical typesetting based on KaTeX from Khan Academy. This is a TiddlyWiki plugin for mathematical typesetting based on KaTeX from Khan Academy.
It is completely self-contained, and doesn't need an Internet connection in order to work. It is completely self-contained, and doesn't need an Internet connection in order to work. It works both in the browser and under Node.js.
//This first version of the plugin cannot be used to generate static content under Node.js, but that capability will come in a future update. (Note that you can still use it when running the client-server configuration under Node.js).//
! Installation ! Installation

View File

@ -10,6 +10,11 @@
], ],
"build": { "build": {
"index": [ "index": [
"--rendertiddler","$:/core/save/all","katexdemo.html","text/plain"] "--rendertiddler","$:/core/save/all","katexdemo.html","text/plain"],
"static": [
"--rendertiddler","$:/core/templates/static.template.html","static.html","text/plain",
"--rendertiddler","$:/core/templates/alltiddlers.template.html","alltiddlers.html","text/plain",
"--rendertiddlers","[!is[system]]","$:/core/templates/static.tiddler.html","static","text/plain",
"--rendertiddler","$:/core/templates/static.template.css","static/static.css","text/plain"]
} }
} }

View File

@ -78,7 +78,9 @@
"type": "application/javascript", "type": "application/javascript",
"title": "$:/plugins/tiddlywiki/katex/katex.min.js", "title": "$:/plugins/tiddlywiki/katex/katex.min.js",
"module-type": "library" "module-type": "library"
} },
"prefix": "(function(document) {\n",
"suffix": "\n})($tw.node ? $tw.fakeDocument : window.document)\n"
} }
] ]
} }

View File

@ -37,7 +37,11 @@ KaTeXWidget.prototype.render = function(parent,nextSibling) {
// Render it into a span // Render it into a span
var span = this.document.createElement("span"); var span = this.document.createElement("span");
try { try {
katex.render(text,span); if($tw.browser) {
katex.render(text,span);
} else {
span.innerHTML = katex.renderToString(text);
}
} catch(ex) { } catch(ex) {
span.className = "tc-error"; span.className = "tc-error";
span.textContent = ex; span.textContent = ex;