Add limit to blocks highlighting

This commit is contained in:
Elian Doran 2024-10-26 23:39:18 +03:00
parent 6078620bf1
commit f80cf0aa02
No known key found for this signature in database

View File

@ -3,6 +3,8 @@ export function initSyntaxHighlighting(editor) {
initTextEditor(editor);
}
const HIGHLIGHT_MAX_BLOCK_COUNT = 500;
const tag = "SyntaxHighlightWidget";
const debugLevels = ["error", "warn", "info", "log", "debug"];
const debugLevel = "debug";
@ -162,6 +164,11 @@ function highlightCodeBlock(codeBlock, writer) {
log("not highlighting plaintext codeblock");
return;
}
// Don't highlight if the code is too big, as the typing performance will be highly degraded.
if (codeBlock.childCount >= HIGHLIGHT_MAX_BLOCK_COUNT) {
return;
}
// highlight.js needs the full text without HTML tags, eg for the
// text