1
1
import type { Element } from 'hast'
2
2
import type { Options as RehypePrettyCodeOptions } from 'rehype-pretty-code'
3
+ import { bundledLanguages , getHighlighter } from 'shikiji'
3
4
import type { Plugin } from 'unified'
4
5
import { visit } from 'unist-util-visit'
5
6
@@ -22,11 +23,18 @@ export const DEFAULT_REHYPE_PRETTY_CODE_OPTIONS: RehypePrettyCodeOptions = {
22
23
}
23
24
delete node . properties [ 'data-line' ]
24
25
} ,
25
- filterMetaString : meta => meta . replace ( CODE_BLOCK_FILENAME_REGEX , '' ) ,
26
26
theme : {
27
27
light : 'github-light' ,
28
28
dark : 'github-dark'
29
- }
29
+ } ,
30
+ getHighlighter ( opts ) {
31
+ return getHighlighter ( {
32
+ ...opts ,
33
+ // Without `getHighlighter` option ```mdx lang is not highlighted...
34
+ langs : Object . keys ( bundledLanguages )
35
+ } )
36
+ } ,
37
+ filterMetaString : meta => meta . replace ( CODE_BLOCK_FILENAME_REGEX , '' )
30
38
}
31
39
32
40
export const rehypeParseCodeMeta : Plugin <
@@ -63,7 +71,8 @@ export const rehypeAttachCodeMeta: Plugin<[], any> = () => ast => {
63
71
const isRehypePrettyCode =
64
72
'data-rehype-pretty-code-figure' in node . properties
65
73
if ( ! isRehypePrettyCode ) return
66
- // remove <div data-rehype-pretty-code-fragment /> element that wraps <pre /> element
74
+
75
+ // remove <figure data-rehype-pretty-code-figure /> element that wraps <pre /> element
67
76
// because we'll wrap with our own <div />
68
77
const preEl : PreElement = Object . assign ( node , node . children [ 0 ] )
69
78
delete preEl . properties [ 'data-theme' ]
@@ -93,7 +102,7 @@ export const rehypeAttachCodeMeta: Plugin<[], any> = () => ast => {
93
102
...Object . entries ( node . properties ) . map ( ( [ name , value ] ) => ( {
94
103
type : 'mdxJsxAttribute' ,
95
104
name,
96
- value
105
+ value : Array . isArray ( value ) ? value . join ( ' ' ) : value
97
106
} ) )
98
107
)
99
108
}
0 commit comments