@@ -17,7 +17,7 @@ if (typeof window !== 'undefined') {
17
17
}
18
18
19
19
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20
- export const PREPARE_MDX_CACHE_BREAKER = 4 ;
20
+ export const PREPARE_MDX_CACHE_BREAKER = 5 ;
21
21
// !!! IMPORTANT !!! Bump this if you change any logic.
22
22
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23
23
@@ -98,6 +98,7 @@ function highlightCodeBlocksRecursively(
98
98
parentPath [ parentPath . length - 1 ] === 'pre' && // Don't highlight inline text
99
99
parentPath [ parentPath . length - 2 ] !== 'Sandpack' // Interactive snippets highlight on the client
100
100
) {
101
+ overrideProps . children = undefined ;
101
102
overrideProps . highlightedCode = prepareCodeBlockChildren (
102
103
props . children ,
103
104
props . meta
@@ -217,7 +218,7 @@ function prepareCodeBlockChildren(
217
218
let buffer = '' ;
218
219
let lineIndex = 0 ;
219
220
let lineOutput = [ ] ;
220
- let finalOutput = [ ] ;
221
+ let finalOutput : Array < React . ReactNode > = [ ] ;
221
222
for ( let i = 0 ; i < code . length ; i ++ ) {
222
223
if ( tokenEnds . has ( i ) ) {
223
224
if ( ! currentToken ) {
@@ -277,30 +278,35 @@ function prepareCodeBlockChildren(
277
278
}
278
279
}
279
280
if ( code [ i ] === '\n' ) {
280
- lineOutput . push ( buffer ) ;
281
+ lineOutput . push ( buffer , < br /> ) ;
281
282
buffer = '' ;
282
- finalOutput . push (
283
- < div
284
- key = { lineIndex }
285
- className = { 'cm-line ' + ( highlightedLines . get ( lineIndex ) ?? '' ) } >
286
- { lineOutput }
287
- < br />
288
- </ div >
289
- ) ;
283
+ if ( highlightedLines . has ( lineIndex ) ) {
284
+ finalOutput . push (
285
+ < div
286
+ key = { lineIndex + 'l' }
287
+ className = { highlightedLines . get ( lineIndex ) } >
288
+ { lineOutput }
289
+ </ div >
290
+ ) ;
291
+ } else {
292
+ finalOutput = [ ...finalOutput , ...lineOutput ] ;
293
+ }
290
294
lineOutput = [ ] ;
291
295
lineIndex ++ ;
292
296
} else {
293
297
buffer += code [ i ] ;
294
298
}
295
299
}
296
300
lineOutput . push ( buffer ) ;
297
- finalOutput . push (
298
- < div
299
- key = { lineIndex }
300
- className = { 'cm-line ' + ( highlightedLines . get ( lineIndex ) ?? '' ) } >
301
- { lineOutput }
302
- </ div >
303
- ) ;
301
+ if ( highlightedLines . has ( lineIndex ) ) {
302
+ finalOutput . push (
303
+ < div key = { lineIndex + 'l' } className = { highlightedLines . get ( lineIndex ) } >
304
+ { lineOutput }
305
+ </ div >
306
+ ) ;
307
+ } else {
308
+ finalOutput = [ ...finalOutput , ...lineOutput ] ;
309
+ }
304
310
return finalOutput ;
305
311
}
306
312
@@ -371,7 +377,7 @@ function getLineDecorators(
371
377
const linesToHighlight = getHighlightLines ( meta ) ;
372
378
const highlightedLineConfig = linesToHighlight . map ( ( line ) => {
373
379
return {
374
- className : 'bg-github-highlight dark:bg-opacity-10 ' ,
380
+ className : 'hl-line ' ,
375
381
line,
376
382
} ;
377
383
} ) ;
0 commit comments