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({
2222 }
2323 }
2424
25- const r = await light ( code , lang as any , theme )
25+ try {
26+ const r = await light ( code , lang as any , theme )
2627
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+ } ) )
3334
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+ }
3544}
You can’t perform that action at this time.
0 commit comments