import { useEffect, useRef, useState } from "react"; import Code20Regular from "@ricons/fluent/Code20Regular"; import Prism from "prismjs"; import "prismjs/plugins/line-numbers/prism-line-numbers"; import "prismjs/plugins/line-numbers/prism-line-numbers.css"; // import "prismjs/components/prism"; import "prismjs/components/prism-javascript"; import "prismjs/components/prism-typescript"; import "prismjs/components/prism-bash"; import "prismjs/components/prism-css"; interface IProps { /** * @description prism 渲染的代码文档字符串 */ raw: string; /** * 语言类型 */ lang: string; } export default function Code(props: IProps) { const [visible, setVisible] = useState(false); const codeRef = useRef(); useEffect(() => { Prism.highlightElement(codeRef.current); }, [props.raw]); return (
setVisible((v) => !v)} >
        
          {props.raw}
        
      
); }