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

Change katex limits #27823

Merged
merged 3 commits into from
Oct 29, 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: 12 additions & 2 deletions web_src/js/markup/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,28 @@ export async function renderMath() {
import(/* webpackChunkName: "katex" */'katex/dist/katex.css'),
]);

const MAX_CHARS = 1000;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want a setting for this like with Mermaid?

const {mermaidMaxSourceCharacters} = window.config;

Copy link
Member

@delvh delvh Oct 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of this addition.
Isn't 1000 chars too restrictive?
That's only four tweets, and there are many comments larger than that.
Even more so if they contain latex code which spikes char usage up tremendously.
Especially as that is per comment instead of per recognized latex string.

As I see it, we can either remove it, or we choose the value that GitLab for example uses.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitLab uses 1000. Why do you think it's the whole comment? source is just the <code> block with the math code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I should have expanded the code a little.
The el.textContent looked to me like it would be the whole comment, not the math block.

const MAX_SIZE = 25;
const MAX_EXPAND = 1000;

for (const el of els) {
const target = targetElement(el);
if (target.hasAttribute('data-render-done')) continue;
const source = el.textContent;

if (source.length > MAX_CHARS) {
displayError(target, new Error(`Math source of ${source.length} characters exceeds the maximum allowed length of ${MAX_CHARS}.`));
continue;
}

const displayMode = el.classList.contains('display');
const nodeName = displayMode ? 'p' : 'span';

try {
const tempEl = document.createElement(nodeName);
katex.render(source, tempEl, {
maxSize: 25,
maxExpand: 50,
maxSize: MAX_SIZE,
maxExpand: MAX_EXPAND,
displayMode,
});
target.replaceWith(tempEl);
Expand Down