({ code, options, className, withCopy = true }: HighlightCodeProps)
| 13 | }); |
| 14 | |
| 15 | export function HighlightCode({ code, options, className, withCopy = true }: HighlightCodeProps) { |
| 16 | const { copyFn } = useCopyToClipboard(); |
| 17 | const [hovered, setHovered] = useState(false); |
| 18 | const { themeMode } = useSettings(); |
| 19 | |
| 20 | return ( |
| 21 | <div className={cn("w-full relative group", className)} onMouseEnter={() => setHovered(true)} onMouseLeave={() => setHovered(false)}> |
| 22 | {withCopy && hovered && ( |
| 23 | <Button variant="outline" size="icon" className="absolute top-2 right-2 bg-accent" onClick={() => copyFn(code)}> |
| 24 | <Icon icon="eva:copy-fill" size={24} /> |
| 25 | </Button> |
| 26 | )} |
| 27 | <div |
| 28 | // biome-ignore lint/security/noDangerouslySetInnerHtml: <explanation> |
| 29 | dangerouslySetInnerHTML={{ |
| 30 | __html: highlighter.codeToHtml(code, { |
| 31 | lang: options?.lang || "typescript", |
| 32 | theme: options?.theme || (themeMode === "dark" ? "min-dark" : "snazzy-light"), |
| 33 | transformers: [ |
| 34 | { |
| 35 | pre(node) { |
| 36 | this.addClassToHast(node, "p-3 rounded-md"); |
| 37 | }, |
| 38 | }, |
| 39 | ], |
| 40 | ...options, |
| 41 | }), |
| 42 | }} |
| 43 | /> |
| 44 | </div> |
| 45 | ); |
| 46 | } |
nothing calls this directly
no test coverage detected