diff --git a/src/components/markdown/MarkdownRender.tsx b/src/components/markdown/MarkdownRender.tsx index 9b8208872..235e9c493 100644 --- a/src/components/markdown/MarkdownRender.tsx +++ b/src/components/markdown/MarkdownRender.tsx @@ -3,6 +3,9 @@ import ReactMarkdown from "react-markdown"; import rehypeKatex from "rehype-katex"; import rehypeMathjax from "rehype-mathjax"; import remarkMath from "remark-math"; +import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; +import { coy } from "react-syntax-highlighter/dist/esm/styles/prism"; +import copy from "copy-to-clipboard"; interface MarkdownRenderProps { content: string; @@ -23,8 +26,54 @@ const MarkdownRender: React.FC = (props) => { children={props.content} remarkPlugins={[remarkMath]} rehypePlugins={getRehypePlugins()} + components={{ + code({ node, className, children, ...props }) { + const match = /language-(\w+)/.exec(className || ""); + const language = match ? match[1] : "text"; + + return match ? ( + + ) : ( + + {children} + + ); + }, + }} /> ); }; +interface CodeBlockProps { + language: string; + value: string; + className?: string; +} + +const CodeBlock: React.FC = ({ + language, + value, + className, +}) => { + const handleCopy = () => { + copy(value); + }; + + return ( +
+ + {value} +
+ ); +}; + export default MarkdownRender; diff --git a/src/components/problem/ProblemTable.tsx b/src/components/problem/ProblemTable.tsx index 80064ea20..afc3d8333 100644 --- a/src/components/problem/ProblemTable.tsx +++ b/src/components/problem/ProblemTable.tsx @@ -30,9 +30,7 @@ const ProblemTable: React.FC = (props) => { {columns.map((column) => { - if (column.uid === "actions" && !props.showActions) { - return null; - } + if (column.uid === "actions" && !props.showActions) return null; return {column.name}; })} @@ -51,16 +49,7 @@ const ProblemTable: React.FC = (props) => { > {problemInfo.title} -
- {problemInfo.tags.map((tag) => ( -
- {tag.name} -
- ))} -
+ {props.showActions && ( @@ -106,6 +95,21 @@ const ProblemTable: React.FC = (props) => { ); }; +const ProblemTags: React.FC<{ tags: { name: string }[] }> = (props) => { + return ( +
+ {props.tags.map((tag) => ( +
+ {tag.name} +
+ ))} +
+ ); +}; + interface ActionsProps { onClickDelete: () => void; } diff --git a/src/mocks/rest/problem.ts b/src/mocks/rest/problem.ts index 77e065c9c..e66ab6186 100644 --- a/src/mocks/rest/problem.ts +++ b/src/mocks/rest/problem.ts @@ -16,23 +16,26 @@ Output a string with format: \`Hello! %s\`. ## Input -- The first line contains a string \`s\`. +The first line contains a string \`s\`. + +- The length of string \`s\` is at most 100. +- The string contains only lowercase and uppercase letters. ## Output -- Output a string \`Hello! %s\`. +Output a string \`Hello! %s\`. ## Example ### Input: -\`\`\` +\`\`\`text world! \`\`\` ### Output: -\`\`\` +\`\`\`text Hello! world! \`\`\` diff --git a/src/pages/Problem.tsx b/src/pages/Problem.tsx index 7cf177445..5a761436e 100644 --- a/src/pages/Problem.tsx +++ b/src/pages/Problem.tsx @@ -43,7 +43,7 @@ const Problem: React.FC = () => { )}
-
+

{getProblem()?.title}