Skip to content

Commit ee37edc

Browse files
authored
Fix environments for KaTeX and error reporting (#22453) (#22473)
Backport #22453 In #22447 it was noticed that display environments were not working correctly. This was due to the setting displayMode not being set. Further it was noticed that the error was not being displayed correctly. This PR fixes both of these issues by forcibly setting the displayMode setting and corrects an error in displayError. Fix #22447 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 29bbfcc commit ee37edc

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

web_src/js/markup/math.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function displayError(el, err) {
22
const target = targetElement(el);
3-
target.remove('is-loading');
3+
target.classList.remove('is-loading');
44
const errorNode = document.createElement('div');
55
errorNode.setAttribute('class', 'ui message error markup-block-error mono');
66
errorNode.textContent = err.str || err.message || String(err);
@@ -23,12 +23,16 @@ export async function renderMath() {
2323

2424
for (const el of els) {
2525
const source = el.textContent;
26-
const options = {display: el.classList.contains('display')};
26+
const displayMode = el.classList.contains('display');
27+
const nodeName = displayMode ? 'p' : 'span';
2728

2829
try {
29-
const markup = katex.renderToString(source, options);
30-
const tempEl = document.createElement(options.display ? 'p' : 'span');
31-
tempEl.innerHTML = markup;
30+
const tempEl = document.createElement(nodeName);
31+
katex.render(source, tempEl, {
32+
maxSize: 25,
33+
maxExpand: 50,
34+
displayMode,
35+
});
3236
targetElement(el).replaceWith(tempEl);
3337
} catch (error) {
3438
displayError(el, error);

0 commit comments

Comments
 (0)