From c7ffeec3647cf7c9e0270ed71f5c115234fdede6 Mon Sep 17 00:00:00 2001 From: Steven Hall Date: Sat, 13 Apr 2024 20:40:04 +0100 Subject: [PATCH] limit on blocks --- .../DocumentView/CodeBlock/highlight.ts | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/components/DocumentView/CodeBlock/highlight.ts b/src/components/DocumentView/CodeBlock/highlight.ts index 08e3f986cc..3ac6c6b0c2 100644 --- a/src/components/DocumentView/CodeBlock/highlight.ts +++ b/src/components/DocumentView/CodeBlock/highlight.ts @@ -37,6 +37,7 @@ type PositionedToken = ThemedToken & { start: number; end: number }; */ let lineCount = 0; let tokenCount = 0; +let blockCount = 0; const LINE_LIMIT = 10000; const runner = asyncMutexFunction(); @@ -60,7 +61,7 @@ export async function highlight(block: DocumentBlockCode): Promise { const start = Date.now(); - console.log(`start ${block.key} ${tokenCount} tokens ${lineCount} lines`) + // console.log(`start ${block.key} ${tokenCount} tokens ${lineCount} lines`) const inlines: InlineIndexed[] = []; const code = getPlainCodeBlock(block, inlines); @@ -71,9 +72,13 @@ export async function highlight(block: DocumentBlockCode): Promise= 100) { + return plainHighlighting(block); + } - const lines = highlighter.codeToTokensBase(code.replace('\\', '').replaceAll(/[^\x00-\x7F]+/gi, ''), { + const lines = highlighter.codeToTokensBase(code, { lang: langName, tokenizeMaxLineLength: 120, }); @@ -107,9 +112,14 @@ export async function highlight(block: DocumentBlockCode): Promise 150) { + // console.log(`--- start ---`) + // console.log(code); + // console.log(`--- end ---`) + console.log( + `end ${block.key} ${blockCount} ${duration}ms lines:${block.nodes.length} code len: ${code.length} lineCountBefore: ${lineCount} tokenCount: ${tokenCount} created lines: ${result.length} langs:${highlighter.getLoadedLanguages().join(',')}`, + ); + // } return result; }); } @@ -340,6 +350,7 @@ const loadHighlighter = singleton(async () => { // loads it on its own. // // Otherwise for Vercel/Cloudflare, we need to load it ourselves. + console.log('load the wasm'); await loadWasm((obj) => WebAssembly.instantiate(onigWasm, obj)); } const highlighter = await getHighlighter({