Skip to content

Commit afa3c6b

Browse files
committed
less languages
1 parent 20193aa commit afa3c6b

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

src/components/highlightCode.tsx

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,21 @@ import {jsx, jsxs} from 'react/jsx-runtime';
33
import {toJsxRuntime} from 'hast-util-to-jsx-runtime';
44
import {Nodes} from 'hastscript/lib/create-h';
55
import 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';
116
import 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';
197
import typescript from 'refractor/lang/typescript.js';
208
import {refractor} from 'refractor/lib/core.js';
219

2210
refractor.register(bash);
2311
refractor.register(json);
2412
refractor.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

3817
export 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

Comments
 (0)