diff --git a/frontend/src/components/CodeBlock.jsx b/frontend/src/components/CodeBlock.jsx new file mode 100644 index 0000000..ea0ce16 --- /dev/null +++ b/frontend/src/components/CodeBlock.jsx @@ -0,0 +1,48 @@ +import React, { useState } from 'react'; +import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; +import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism'; +import { CopyOutlined, CheckOutlined } from '@ant-design/icons'; +import { Button, Tooltip } from 'antd'; + +const CodeBlock = ({ language, children, ...props }) => { + const [copied, setCopied] = useState(false); + + const handleCopy = () => { + navigator.clipboard.writeText(String(children).replace(/\n$/, '')); + setCopied(true); + setTimeout(() => setCopied(false), 2000); + }; + + return ( +
+ +
+ ); +}; + +export default CodeBlock; diff --git a/frontend/src/pages/ForumDetail.jsx b/frontend/src/pages/ForumDetail.jsx index 965c160..a944022 100644 --- a/frontend/src/pages/ForumDetail.jsx +++ b/frontend/src/pages/ForumDetail.jsx @@ -14,6 +14,8 @@ import rehypeRaw from 'rehype-raw'; import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism'; import 'katex/dist/katex.min.css'; +import styles from './ForumDetail.module.less'; +import CodeBlock from '../components/CodeBlock'; const { Title, Text } = Typography; const { TextArea } = Input; @@ -133,14 +135,12 @@ const ForumDetail = () => { code({node, inline, className, children, ...props}) { const match = /language-(\w+)/.exec(className || '') return !inline && match ? ( - {String(children).replace(/\n$/, '')} - + ) : ( {children} @@ -226,7 +226,7 @@ const ForumDetail = () => { fontSize: 16, lineHeight: 1.8, minHeight: 200, - }} className="markdown-body"> + }} className={styles['markdown-body']}> { #{index + 1} -
+