Skip to content

Commit

Permalink
run blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
emmerich committed Apr 13, 2024
1 parent b56490d commit b7b0490
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/components/DocumentView/CodeBlock/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ export async function highlight(block: DocumentBlockCode): Promise<HighlightLine
return plainHighlighting(block);
}

lineCount += block.nodes.length;
blockCount++;
const overLimit = await renderer.runBlocking(async () => {
lineCount += block.nodes.length;
blockCount++;
return lineCount > LINE_LIMIT;
})

if (lineCount > LINE_LIMIT) {
if (overLimit) {
return plainHighlighting(block);
}

Expand All @@ -60,14 +63,12 @@ export async function highlight(block: DocumentBlockCode): Promise<HighlightLine
return a.start - b.start;
});

const lines = await renderer.runBlocking(async () => {
const highlighter = await loadHighlighter();
await loadHighlighterLanguage(highlighter, langName);
const highlighter = await loadHighlighter();
await loadHighlighterLanguage(highlighter, langName);

return highlighter.codeToTokensBase(code, {
lang: langName,
tokenizeMaxLineLength: 120,
});
const lines = highlighter.codeToTokensBase(code, {
lang: langName,
tokenizeMaxLineLength: 120,
});

console.log(
Expand Down

0 comments on commit b7b0490

Please sign in to comment.