From fca31465b4b08203fe5fb2cce11d2c025573d1f0 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Sat, 7 Aug 2021 19:13:08 +0200 Subject: [PATCH] Display error Mathjax correctly --- ts/editable/mathjax.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/ts/editable/mathjax.ts b/ts/editable/mathjax.ts index 0a60cf28d..623602704 100644 --- a/ts/editable/mathjax.ts +++ b/ts/editable/mathjax.ts @@ -4,11 +4,10 @@ import { mathIcon } from "./icons"; const parser = new DOMParser(); -const errorPattern = /(.*?)<\/title>/gsu; function getStyle(): HTMLStyleElement { const style = document.createElement("style") as HTMLStyleElement; - const css = `svg { color: white; fill: white; font-size: 20px; }`; + const css = `svg { color: white; font-size: 20px; }`; style.appendChild(document.createTextNode(css)); return style; @@ -36,13 +35,13 @@ export function convertMathjax(input: string): string { return getEmptyIcon(); } - if (!svg.innerHTML.includes("data-mjx-error")) { + if (svg.innerHTML.includes("data-mjx-error")) { + svg.querySelector("rect").setAttribute("fill", "yellow"); + svg.querySelector("text").setAttribute("color", "red"); + } else { const style = getStyle(); svg.insertBefore(style, svg.children[0]); - - return svg.outerHTML; - } else { - const match = errorPattern.exec(svg.innerHTML); - throw match ? match[1] : "Unknown error"; } + + return svg.outerHTML; }