File tree Expand file tree Collapse file tree 1 file changed +17
-8
lines changed
packages/mdx/src/highlighter Expand file tree Collapse file tree 1 file changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -22,14 +22,23 @@ export async function highlight({
22
22
}
23
23
}
24
24
25
- const r = await light ( code , lang as any , theme )
25
+ try {
26
+ const r = await light ( code , lang as any , theme )
26
27
27
- const lines = r . lines . map ( line => ( {
28
- tokens : line . map ( token => ( {
29
- content : token . content ,
30
- props : { style : token . style } ,
31
- } ) ) ,
32
- } ) )
28
+ const lines = r . lines . map ( line => ( {
29
+ tokens : line . map ( token => ( {
30
+ content : token . content ,
31
+ props : { style : token . style } ,
32
+ } ) ) ,
33
+ } ) )
33
34
34
- return { lines, lang }
35
+ return { lines, lang }
36
+ } catch ( e ) {
37
+ // TODO check error is "missing grammar"
38
+ console . warn (
39
+ "[Code Hike warning]" ,
40
+ `${ lang } is not a valid language, no syntax highlighting will be applied.`
41
+ )
42
+ return highlight ( { code, lang : "text" , theme } )
43
+ }
35
44
}
You can’t perform that action at this time.
0 commit comments