diff options
author | silverwind <me@silverwind.io> | 2022-11-17 02:04:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-17 09:04:09 +0800 |
commit | c144942b23eb6e05a60526cc6d2b88b488ca75dd (patch) | |
tree | 7efc6f04142231c60855844286a76f01936e7b4b /web_src/js/markup/math.js | |
parent | 92dd24716d22bbb849365605a13b94e8897d06fd (diff) | |
download | gitea-c144942b23eb6e05a60526cc6d2b88b488ca75dd.tar.gz gitea-c144942b23eb6e05a60526cc6d2b88b488ca75dd.zip |
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>
Diffstat (limited to 'web_src/js/markup/math.js')
-rw-r--r-- | web_src/js/markup/math.js | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/web_src/js/markup/math.js b/web_src/js/markup/math.js index 5790a327a5..d4e40d5be2 100644 --- a/web_src/js/markup/math.js +++ b/web_src/js/markup/math.js @@ -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); |