Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions packages/prism-react-renderer/src/components/highlight.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { forwardRef } from "react"
import { InternalHighlightProps } from "../types"
import { useGetLineProps } from "./useGetLineProps"
import { useGetTokenProps } from "./useGetTokenProps"
import { useTokenize } from "./useTokenize"
import themeToDict from "../utils/themeToDict"

export const Highlight = ({
children,
language: _language,
code,
theme,
prism,
}: InternalHighlightProps) => {
const language = _language.toLowerCase()
const themeDictionary = themeToDict(theme, language)
const getLineProps = useGetLineProps(themeDictionary)
const getTokenProps = useGetTokenProps(themeDictionary)
const grammar = prism.languages[language]
const tokens = useTokenize({ prism, language, code, grammar })
export const Highlight = forwardRef<HTMLDivElement, InternalHighlightProps>(
({ children, language: _language, code, theme, prism }, ref) => {
const language = _language.toLowerCase()
const themeDictionary = themeToDict(theme, language)
const getLineProps = useGetLineProps(themeDictionary)
const getTokenProps = useGetTokenProps(themeDictionary)
const grammar = prism.languages[language]
const tokens = useTokenize({ prism, language, code, grammar })

return children({
tokens,
className: `prism-code language-${language}`,
style: themeDictionary != null ? themeDictionary.root : {},
getLineProps,
getTokenProps,
})
}
return children({
tokens,
className: `prism-code language-${language}`,
style: themeDictionary != null ? themeDictionary.root : {},
getLineProps,
getTokenProps,
ref,
})
}
)

Highlight.displayName = "Highlight"
1 change: 1 addition & 0 deletions packages/prism-react-renderer/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export type RenderProps = {
style: CSSProperties
getLineProps: (input: LineInputProps) => LineOutputProps
getTokenProps: (input: TokenInputProps) => TokenOutputProps
ref: React.Ref<HTMLDivElement>
}
export type PrismThemeEntry = {
color?: string
Expand Down
Loading