@@ -3,38 +3,21 @@ import {jsx, jsxs} from 'react/jsx-runtime';
33import { toJsxRuntime } from 'hast-util-to-jsx-runtime' ;
44import { Nodes } from 'hastscript/lib/create-h' ;
55import bash from 'refractor/lang/bash.js' ;
6- import c from 'refractor/lang/c.js' ;
7- import cpp from 'refractor/lang/cpp.js' ;
8- import csharp from 'refractor/lang/csharp.js' ;
9- import go from 'refractor/lang/go.js' ;
10- import java from 'refractor/lang/java.js' ;
116import json from 'refractor/lang/json.js' ;
12- import kotlin from 'refractor/lang/kotlin.js' ;
13- import objectivec from 'refractor/lang/objectivec.js' ;
14- import php from 'refractor/lang/php.js' ;
15- import python from 'refractor/lang/python.js' ;
16- import ruby from 'refractor/lang/ruby.js' ;
17- import rust from 'refractor/lang/rust.js' ;
18- import swift from 'refractor/lang/swift.js' ;
197import typescript from 'refractor/lang/typescript.js' ;
208import { refractor } from 'refractor/lib/core.js' ;
219
2210refractor . register ( bash ) ;
2311refractor . register ( json ) ;
2412refractor . register ( typescript ) ;
25- refractor . register ( python ) ;
26- refractor . register ( java ) ;
27- refractor . register ( c ) ;
28- refractor . register ( cpp ) ;
29- refractor . register ( kotlin ) ;
30- refractor . register ( csharp ) ;
31- refractor . register ( rust ) ;
32- refractor . register ( swift ) ;
33- refractor . register ( ruby ) ;
34- refractor . register ( objectivec ) ;
35- refractor . register ( php ) ;
36- refractor . register ( go ) ;
13+
14+ // If a new language should be supported, add it here and register it in refractor above
15+ export const SUPPORTED_LANGUAGES = [ 'bash' , 'json' , 'typescript' ] ;
3716
3817export function codeToJsx ( code : string , lang = 'json' ) {
18+ if ( ! SUPPORTED_LANGUAGES . includes ( lang ) ) {
19+ // eslint-disable-next-line no-console
20+ console . error ( `Unsupported language for syntax highlighting: ${ lang } ` ) ;
21+ }
3922 return toJsxRuntime ( refractor . highlight ( code , lang ) as Nodes , { Fragment, jsx, jsxs} ) ;
4023}
0 commit comments