-
Notifications
You must be signed in to change notification settings - Fork 343
Expand file tree
/
Copy pathSyntaxHighlighter.tsx
More file actions
44 lines (41 loc) · 1.33 KB
/
SyntaxHighlighter.tsx
File metadata and controls
44 lines (41 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// @ts-expect-error
import { PrismLight as SyntaxHighlighter } from 'react-syntax-highlighter/dist/esm/index';
// @ts-expect-error
import tsx from 'react-syntax-highlighter/dist/esm/languages/prism/tsx';
// @ts-expect-error
import ts from 'react-syntax-highlighter/dist/esm/languages/prism/typescript';
// @ts-expect-error
import css from 'react-syntax-highlighter/dist/esm/languages/prism/css';
SyntaxHighlighter.registerLanguage('tsx', tsx);
SyntaxHighlighter.registerLanguage('ts', ts);
SyntaxHighlighter.registerLanguage('css', css);
import { Box } from '../system';
import Text from '../Typography/Text';
import * as styles from './SyntaxHighlighter.css';
export interface CodeProps {
language: string;
children: string;
tokenized?: boolean;
}
export default ({ language, children, tokenized }: CodeProps) => {
return (
<Box className={styles.root}>
<Text size="code" component="div" baseline={false}>
{tokenized ? (
<code
className={`language-${language}`}
data-language={language}
dangerouslySetInnerHTML={{ __html: children }}
/>
) : (
<SyntaxHighlighter
language={language}
style={{ [`pre[class*="language-"]`]: {} }}
>
{children}
</SyntaxHighlighter>
)}
</Text>
</Box>
);
};