From a37a73dede2ce8587d32a7b855f7c33eda3db692 Mon Sep 17 00:00:00 2001 From: Edoardo Morassutto Date: Sun, 1 Nov 2020 19:00:39 +0100 Subject: [PATCH] fix: inline math interpreted as attributes (#2645) When using inline math ($e^{-x^2}$) the curly braces are interpreted as attributes by markdown-it-attrs. Since most of the times they are not valid attributes they simply get removed. This patch escapes the curly braces (the default attribute delimiter), fixing the KaTeX rendering errors. It would be nice to simply skip that rule for `katex_inline` block types but as far as I know markdown-it-attrs doesn't have such an option. Fixes #1581 --- client/components/editor/common/katex.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/components/editor/common/katex.js b/client/components/editor/common/katex.js index 3c17b1fb..27bc11ba 100644 --- a/client/components/editor/common/katex.js +++ b/client/components/editor/common/katex.js @@ -81,7 +81,14 @@ export default { if (!silent) { token = state.push('katex_inline', 'math', 0) token.markup = '$' - token.content = state.src.slice(start, match) + token.content = state.src + // Extract the math part without the $ + .slice(start, match) + // Escape the curly braces since they will be interpreted as + // attributes by markdown-it-attrs (the "curly_attributes" + // core rule) + .replaceAll("{", "{{") + .replaceAll("}", "}}") } state.pos = match + 1