From 2e0195f65803a050cdc35ca1155312695b756d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Tue, 25 May 2021 14:36:55 +0200 Subject: [PATCH] Make sure math equations are rendered sequentially (#294) --- assets/js/cell/markdown.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/assets/js/cell/markdown.js b/assets/js/cell/markdown.js index f49f217cd..cb1c5df01 100644 --- a/assets/js/cell/markdown.js +++ b/assets/js/cell/markdown.js @@ -79,18 +79,18 @@ class Markdown { // Replaces TeX formulas in string with rendered HTML using KaTeX. __renderMathInString(string) { - const options = { - throwOnError: false, - errorColor: "inherit", - }; + return string.replace( + /(\${1,2})([\s\S]*?)\1/g, + (match, delimiter, math) => { + const displayMode = delimiter === "$$"; - return string - .replace(/\$\$([\s\S]*?)\$\$/g, (match, math) => { - return katex.renderToString(math, { ...options, displayMode: true }); - }) - .replace(/\$([\s\S]*?)\$/g, (match, math) => { - return katex.renderToString(math, options); - }); + return katex.renderToString(math.trim(), { + displayMode, + throwOnError: false, + errorColor: "inherit", + }); + } + ); } }