Skip to content

Commit b7b0490

Browse files
committed
run blocking
1 parent b56490d commit b7b0490

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/components/DocumentView/CodeBlock/highlight.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ export async function highlight(block: DocumentBlockCode): Promise<HighlightLine
4646
return plainHighlighting(block);
4747
}
4848

49-
lineCount += block.nodes.length;
50-
blockCount++;
49+
const overLimit = await renderer.runBlocking(async () => {
50+
lineCount += block.nodes.length;
51+
blockCount++;
52+
return lineCount > LINE_LIMIT;
53+
})
5154

52-
if (lineCount > LINE_LIMIT) {
55+
if (overLimit) {
5356
return plainHighlighting(block);
5457
}
5558

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

63-
const lines = await renderer.runBlocking(async () => {
64-
const highlighter = await loadHighlighter();
65-
await loadHighlighterLanguage(highlighter, langName);
66+
const highlighter = await loadHighlighter();
67+
await loadHighlighterLanguage(highlighter, langName);
6668

67-
return highlighter.codeToTokensBase(code, {
68-
lang: langName,
69-
tokenizeMaxLineLength: 120,
70-
});
69+
const lines = highlighter.codeToTokensBase(code, {
70+
lang: langName,
71+
tokenizeMaxLineLength: 120,
7172
});
7273

7374
console.log(

0 commit comments

Comments
 (0)