@@ -37,6 +37,7 @@ type PositionedToken = ThemedToken & { start: number; end: number };
37
37
*/
38
38
let lineCount = 0 ;
39
39
let tokenCount = 0 ;
40
+ let blockCount = 0 ;
40
41
const LINE_LIMIT = 10000 ;
41
42
42
43
const runner = asyncMutexFunction ( ) ;
@@ -60,7 +61,7 @@ export async function highlight(block: DocumentBlockCode): Promise<HighlightLine
60
61
61
62
return runner . runBlocking ( async ( ) => {
62
63
const start = Date . now ( ) ;
63
- console . log ( `start ${ block . key } ${ tokenCount } tokens ${ lineCount } lines` )
64
+ // console.log(`start ${block.key} ${tokenCount} tokens ${lineCount} lines`)
64
65
const inlines : InlineIndexed [ ] = [ ] ;
65
66
const code = getPlainCodeBlock ( block , inlines ) ;
66
67
@@ -71,9 +72,13 @@ export async function highlight(block: DocumentBlockCode): Promise<HighlightLine
71
72
const highlighter = await loadHighlighter ( ) ;
72
73
await loadHighlighterLanguage ( highlighter , langName ) ;
73
74
lineCount += block . nodes . length ;
75
+ blockCount += 1 ;
74
76
77
+ if ( blockCount >= 100 ) {
78
+ return plainHighlighting ( block ) ;
79
+ }
75
80
76
- const lines = highlighter . codeToTokensBase ( code . replace ( '\\' , '' ) . replaceAll ( / [ ^ \x00 - \x7F ] + / gi , '' ) , {
81
+ const lines = highlighter . codeToTokensBase ( code , {
77
82
lang : langName ,
78
83
tokenizeMaxLineLength : 120 ,
79
84
} ) ;
@@ -107,9 +112,14 @@ export async function highlight(block: DocumentBlockCode): Promise<HighlightLine
107
112
} ) ;
108
113
109
114
const duration = Date . now ( ) - start ;
110
- console . log (
111
- `end ${ block . key } ${ duration } ms code len: ${ code . length } lineCountBefore: ${ lineCount } tokenCount: ${ tokenCount } created lines: ${ result . length } langs:${ highlighter . getLoadedLanguages ( ) . join ( ',' ) } ` ,
112
- ) ;
115
+ // if (duration > 150) {
116
+ // console.log(`--- start ---`)
117
+ // console.log(code);
118
+ // console.log(`--- end ---`)
119
+ console . log (
120
+ `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 ( ',' ) } ` ,
121
+ ) ;
122
+ // }
113
123
return result ;
114
124
} ) ;
115
125
}
@@ -340,6 +350,7 @@ const loadHighlighter = singleton(async () => {
340
350
// loads it on its own.
341
351
//
342
352
// Otherwise for Vercel/Cloudflare, we need to load it ourselves.
353
+ console . log ( 'load the wasm' ) ;
343
354
await loadWasm ( ( obj ) => WebAssembly . instantiate ( onigWasm , obj ) ) ;
344
355
}
345
356
const highlighter = await getHighlighter ( {
0 commit comments