|
| 1 | +import { forwardRef } from "react" |
1 | 2 | import { InternalHighlightProps } from "../types" |
2 | 3 | import { useGetLineProps } from "./useGetLineProps" |
3 | 4 | import { useGetTokenProps } from "./useGetTokenProps" |
4 | 5 | import { useTokenize } from "./useTokenize" |
5 | 6 | import themeToDict from "../utils/themeToDict" |
6 | 7 |
|
7 | | -export const Highlight = ({ |
8 | | - children, |
9 | | - language: _language, |
10 | | - code, |
11 | | - theme, |
12 | | - prism, |
13 | | -}: InternalHighlightProps) => { |
14 | | - const language = _language.toLowerCase() |
15 | | - const themeDictionary = themeToDict(theme, language) |
16 | | - const getLineProps = useGetLineProps(themeDictionary) |
17 | | - const getTokenProps = useGetTokenProps(themeDictionary) |
18 | | - const grammar = prism.languages[language] |
19 | | - const tokens = useTokenize({ prism, language, code, grammar }) |
| 8 | +export const Highlight = forwardRef<HTMLDivElement, InternalHighlightProps>( |
| 9 | + ({ children, language: _language, code, theme, prism }, ref) => { |
| 10 | + const language = _language.toLowerCase() |
| 11 | + const themeDictionary = themeToDict(theme, language) |
| 12 | + const getLineProps = useGetLineProps(themeDictionary) |
| 13 | + const getTokenProps = useGetTokenProps(themeDictionary) |
| 14 | + const grammar = prism.languages[language] |
| 15 | + const tokens = useTokenize({ prism, language, code, grammar }) |
20 | 16 |
|
21 | | - return children({ |
22 | | - tokens, |
23 | | - className: `prism-code language-${language}`, |
24 | | - style: themeDictionary != null ? themeDictionary.root : {}, |
25 | | - getLineProps, |
26 | | - getTokenProps, |
27 | | - }) |
28 | | -} |
| 17 | + return children({ |
| 18 | + tokens, |
| 19 | + className: `prism-code language-${language}`, |
| 20 | + style: themeDictionary != null ? themeDictionary.root : {}, |
| 21 | + getLineProps, |
| 22 | + getTokenProps, |
| 23 | + ref, |
| 24 | + }) |
| 25 | + } |
| 26 | +) |
| 27 | + |
| 28 | +Highlight.displayName = "Highlight" |
0 commit comments