Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 04a2191

Browse files
authored
fix selector so maths support doesn't mangle divs (#12433)
1 parent 193237f commit 04a2191

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/HtmlUtils.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ export function bodyToHtml(content: IContent, highlights: Optional<string[]>, op
348348
isHtmlMessage = !isPlainText;
349349

350350
if (isHtmlMessage && SettingsStore.getValue("feature_latex_maths")) {
351-
[...phtml.querySelectorAll<HTMLElement>("div, span[data-mx-maths]")].forEach((e) => {
351+
[...phtml.querySelectorAll<HTMLElement>("div[data-mx-maths], span[data-mx-maths]")].forEach((e) => {
352352
e.outerHTML = katex.renderToString(decode(e.getAttribute("data-mx-maths")), {
353353
throwOnError: false,
354354
displayMode: e.tagName == "DIV",

test/HtmlUtils-test.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ describe("bodyToHtml", () => {
166166
});
167167
expect(html).toMatchSnapshot();
168168
});
169+
170+
it("should not mangle divs", () => {
171+
const html = getHtml({
172+
body: "hello world",
173+
msgtype: "m.text",
174+
formatted_body: "<p>hello</p><div>world</div>",
175+
format: "org.matrix.custom.html",
176+
});
177+
expect(html).toMatchSnapshot();
178+
});
169179
});
170180
});
171181

test/__snapshots__/HtmlUtils-test.tsx.snap

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
exports[`bodyToHtml feature_latex_maths should not mangle code blocks 1`] = `"<p>hello</p><pre><code>$\\xi$</code></pre><p>world</p>"`;
44

5+
exports[`bodyToHtml feature_latex_maths should not mangle divs 1`] = `"<p>hello</p><div>world</div>"`;
6+
57
exports[`bodyToHtml feature_latex_maths should render block katex 1`] = `"<p>hello</p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>ξ</mi></mrow><annotation encoding="application/x-tex">\\xi</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.04601em;">ξ</span></span></span></span></span><p>world</p>"`;
68

79
exports[`bodyToHtml feature_latex_maths should render inline katex 1`] = `"hello <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ξ</mi></mrow><annotation encoding="application/x-tex">\\xi</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.04601em;">ξ</span></span></span></span> world"`;

0 commit comments

Comments
 (0)