Skip to content

Commit

Permalink
Tweak katex options
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
silverwind committed Nov 15, 2022
1 parent f311d15 commit 2912ba9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions web_src/js/markup/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ export async function renderMath() {

for (const el of els) {
const source = el.textContent;
const options = {display: el.classList.contains('display')};
const nodeName = el.classList.contains('display') ? '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,
});
targetElement(el).replaceWith(tempEl);
} catch (error) {
displayError(el, error);
Expand Down

0 comments on commit 2912ba9

Please sign in to comment.