Skip to content

Commit

Permalink
Tweak katex options (go-gitea#21828)
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

Co-authored-by: John Olheiser <john.olheiser@gmail.com>
  • Loading branch information
2 people authored and fsologureng committed Nov 22, 2022
1 parent af4a070 commit d936168
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 d936168

Please sign in to comment.