Skip to content

Commit c144942

Browse files
Tweak katex options (#21828)
- Render directly into DOM, skipping string conversion - Add limiting options to prevent excessive size/macros - Remove invalid `display` option previously passed Ref: https://katex.org/docs/options.html Co-authored-by: John Olheiser <john.olheiser@gmail.com>
1 parent 92dd247 commit c144942

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Diff for: web_src/js/markup/math.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ 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 nodeName = el.classList.contains('display') ? 'p' : 'span';
2727

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

0 commit comments

Comments
 (0)