import usePrism, { type OptionalPrismPlugin, type PrismLanguage, } from '@utils/hooks/use-prism'; import { FC, useRef } from 'react'; import styles from './code.module.scss'; export type CodeProps = { /** * An accessible name. */ 'aria-label'?: string; /** * The code to highlight. */ children: string; /** * Filter command line output. Default: false. */ filterOutput?: boolean; /** * The code language. */ language: PrismLanguage; /** * The optional Prism plugins. */ plugins?: OptionalPrismPlugin[]; /** * Filter command line output using the given string. Default: #output# */ outputPattern?: string; }; /** * Code component * * Render a code block with syntax highlighting. */ const Code: FC = ({ children, filterOutput = false, language, plugins = [], outputPattern = '#output#', ...props }) => { const wrapperRef = useRef(null); const { attributes, className } = usePrism({ language, plugins }); const outputAttribute = filterOutput ? { 'data-filter-output': outputPattern } : {}; return (
        {children}
      
); }; export default Code; rmandphilippot.com/refs/?id=de9a9eac060974a7878f2bb5577f2b135596a555'>refslogtreecommitdiffstats
blob: c7700e9695ea5c6c25a65112cd05c1fb65e4cd97 (plain)
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