Skip to content

Commit

Permalink
Fix: unknown code should still render in the app
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdjohnson committed Apr 6, 2024
1 parent 6fc7cc3 commit 92de20d
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/components/CustomCodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,26 @@ const CustomCodeBlock = (props: React.HTMLAttributes<HTMLElement>) => {
}, [className, multiLine])

const { highlightedText, language } = useMemo(() => {
if (languageOverride) {
const hightligted = hljs.highlight(languageOverride, text)
try {
if (languageOverride) {
const hightligted = hljs.highlight(languageOverride, text)

return {
highlightedText: hightligted.value,
language: languageOverride,
}
}
const hightligted = hljs.highlightAuto(text)

return {
highlightedText: hightligted.value,
language: languageOverride,
language: hightligted.language,
}
} catch (e) {
return {
highlightedText: text,
language: languageOverride || undefined,
}
}

const hightligted = hljs.highlightAuto(text)

return {
highlightedText: hightligted.value,
language: hightligted.language,
}
}, [text])

Expand Down

0 comments on commit 92de20d

Please sign in to comment.