From b3df07ae3e190cfb6fc23dbe31c6229fe5e39087 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Wed, 24 Sep 2014 11:50:49 +0200 Subject: [PATCH] Error handling for KaTeX plugin --- editions/katexdemo/tiddlers/HelloThere.tid | 11 +++++++++++ plugins/tiddlywiki/katex/wrapper.js | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/editions/katexdemo/tiddlers/HelloThere.tid b/editions/katexdemo/tiddlers/HelloThere.tid index 9b807f77a..719121c1e 100644 --- a/editions/katexdemo/tiddlers/HelloThere.tid +++ b/editions/katexdemo/tiddlers/HelloThere.tid @@ -63,3 +63,14 @@ For more flexibility the KaTeX widget can also be used via the full widget synta ``` <$latex text="\displaystyle f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi"> + +! Error Handling + +An warning message is displayed if KaTeX detects a problem with the ~LaTeX syntax. For example: + +``` +$$\displaystyle f(x) = \int_{-\infty}^\infinity\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi$$ +``` + +$$\displaystyle f(x) = \int_{-\infty}^\infinity\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi$$ + diff --git a/plugins/tiddlywiki/katex/wrapper.js b/plugins/tiddlywiki/katex/wrapper.js index 36aa9d911..517ff5950 100644 --- a/plugins/tiddlywiki/katex/wrapper.js +++ b/plugins/tiddlywiki/katex/wrapper.js @@ -36,7 +36,12 @@ KaTeXWidget.prototype.render = function(parent,nextSibling) { var text = this.getAttribute("text",this.parseTreeNode.text || ""); // Render it into a span var span = this.document.createElement("span"); - katex.render(text,span); + try { + katex.render(text,span); + } catch(ex) { + span.className = "tc-error"; + span.textContent = ex; + } // Insert it into the DOM parent.insertBefore(span,nextSibling); this.domNodes.push(span);