Skip to content

Commit

Permalink
rm useref
Browse files Browse the repository at this point in the history
  • Loading branch information
nlkluth committed Dec 9, 2024
1 parent 9a6e47b commit db43793
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/prism-react-renderer/src/components/useTokenize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EnvConfig, Language, PrismGrammar, PrismLib } from "../types"
import normalizeTokens from "../utils/normalizeTokens"
import { useMemo, useRef } from "react"
import { useMemo } from "react"

type Options = {
prism: PrismLib
Expand All @@ -10,7 +10,6 @@ type Options = {
}

export const useTokenize = ({ prism, code, grammar, language }: Options) => {
const prismRef = useRef(prism)
return useMemo(() => {
if (grammar == null) return normalizeTokens([code])

Expand All @@ -21,9 +20,15 @@ export const useTokenize = ({ prism, code, grammar, language }: Options) => {
tokens: [],
}

prismRef.current.hooks.run("before-tokenize", prismConfig)
prismConfig.tokens = prismRef.current.tokenize(code, grammar)
prismRef.current.hooks.run("after-tokenize", prismConfig)
prism.hooks.run("before-tokenize", prismConfig)
prismConfig.tokens = prism.tokenize(code, grammar)
prism.hooks.run("after-tokenize", prismConfig)
return normalizeTokens(prismConfig.tokens)
}, [code, grammar, language])
}, [
code,
grammar,
language,
// prism is a stable import
prism,
])
}

0 comments on commit db43793

Please sign in to comment.