Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix environments for KaTeX and error reporting (#22453) #22473

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions web_src/js/markup/math.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function displayError(el, err) {
const target = targetElement(el);
target.remove('is-loading');
target.classList.remove('is-loading');
const errorNode = document.createElement('div');
errorNode.setAttribute('class', 'ui message error markup-block-error mono');
errorNode.textContent = err.str || err.message || String(err);
Expand All @@ -23,12 +23,16 @@ export async function renderMath() {

for (const el of els) {
const source = el.textContent;
const options = {display: el.classList.contains('display')};
const displayMode = el.classList.contains('display');
const nodeName = displayMode ? 'p' : 'span';

try {
const markup = katex.renderToString(source, options);
const tempEl = document.createElement(options.display ? 'p' : 'span');
tempEl.innerHTML = markup;
const tempEl = document.createElement(nodeName);
katex.render(source, tempEl, {
maxSize: 25,
maxExpand: 50,
displayMode,
});
targetElement(el).replaceWith(tempEl);
} catch (error) {
displayError(el, error);
Expand Down