Skip to content

Commit

Permalink
count
Browse files Browse the repository at this point in the history
  • Loading branch information
emmerich committed Apr 13, 2024
1 parent f63ac9e commit 82c9e0e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/components/DocumentView/CodeBlock/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HighlightLine[]> {
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);

Expand Down

0 comments on commit 82c9e0e

Please sign in to comment.