The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useMemo } from "react"; |
| 2 | |
| 3 | import { resolveHighlightLanguage } from "../../lib/highlightLanguage"; |
| 4 | import { highlightCode, type HighlightedLines, type HighlightScheme } from "../../lib/highlights"; |
| 5 | |
| 6 | export function useMarkdownCodeHighlight(input: { |
| 7 | readonly code: string; |
| 8 | readonly enabled: boolean; |
| 9 | readonly language: string | null | undefined; |
| 10 | readonly theme: HighlightScheme; |
| 11 | }): HighlightedLines | null { |
| 12 | const { code, enabled, theme } = input; |
| 13 | const language = input.language?.trim(); |
| 14 | return useMemo( |
| 15 | () => |
| 16 | enabled && language |
| 17 | ? highlightCode(code, resolveHighlightLanguage({ language }), theme) |
| 18 | : null, |
| 19 | [code, enabled, language, theme], |
| 20 | ); |
| 21 | } |