diff --git a/src/components/DocumentView/CodeBlock/highlight.ts b/src/components/DocumentView/CodeBlock/highlight.ts index ef284ef00..cdffe91dc 100644 --- a/src/components/DocumentView/CodeBlock/highlight.ts +++ b/src/components/DocumentView/CodeBlock/highlight.ts @@ -34,16 +34,23 @@ let blockCount = 0; let lineCount = 0; let charCount = 0; +const LINE_LIMIT = 1000; + /** * Highlight a code block while preserving inline elements. */ export async function highlight(block: DocumentBlockCode): Promise { const langName = block.data.syntax ? getLanguageForSyntax(block.data.syntax) : null; + if (!langName) { // Language not found, fallback to plain highlighting return plainHighlighting(block); } + if (lineCount + block.nodes.length > LINE_LIMIT) { + return plainHighlighting(block); + } + const inlines: InlineIndexed[] = []; const code = getPlainCodeBlock(block, inlines);