File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -101,13 +101,14 @@ export default function rehypeHighlight(options) {
101
101
node . properties . className . unshift ( name )
102
102
}
103
103
104
+ const text = toText ( node , { whitespace : 'pre' } )
104
105
/** @type {Root } */
105
106
let result
106
107
107
108
try {
108
109
result = lang
109
- ? lowlight . highlight ( lang , toText ( parent ) , { prefix} )
110
- : lowlight . highlightAuto ( toText ( parent ) , { prefix, subset} )
110
+ ? lowlight . highlight ( lang , text , { prefix} )
111
+ : lowlight . highlightAuto ( text , { prefix, subset} )
111
112
} catch ( error ) {
112
113
const cause = /** @type {Error } */ ( error )
113
114
Original file line number Diff line number Diff line change @@ -366,6 +366,20 @@ test('rehypeHighlight', async function (t) {
366
366
)
367
367
} )
368
368
369
+ await t . test ( 'should support multiple `code`s in a `pre`' , async function ( ) {
370
+ const file = await rehype ( )
371
+ . data ( 'settings' , { fragment : true } )
372
+ . use ( rehypeHighlight ) . process ( `<pre>
373
+ <code class="language-javascript">const a = 1;</code>
374
+ <code class="language-python">printf("x")</code>
375
+ </pre>` )
376
+
377
+ assert . equal (
378
+ String ( file ) ,
379
+ '<pre> <code class="hljs language-javascript"><span class="hljs-keyword">const</span> a = <span class="hljs-number">1</span>;</code>\n <code class="hljs language-python">printf(<span class="hljs-string">"x"</span>)</code>\n</pre>'
380
+ )
381
+ } )
382
+
369
383
await t . test ( 'should reprocess exact' , async function ( ) {
370
384
const file = await rehype ( )
371
385
. data ( 'settings' , { fragment : true } )
You can’t perform that action at this time.
0 commit comments