|
@@ -4,6 +4,7 @@ import rehypeRaw from "rehype-raw";
|
|
|
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
|
|
|
import { vscDarkPlus } from "react-syntax-highlighter/dist/esm/styles/prism";
|
|
|
import { useState } from "react";
|
|
|
+import "./index.less";
|
|
|
|
|
|
interface MarkdownViewerProps {
|
|
|
content: string;
|
|
@@ -38,55 +39,56 @@ const MarkdownViewer: React.FC<MarkdownViewerProps> = ({ content }) => {
|
|
|
setCopiedIndex(index);
|
|
|
setTimeout(() => setCopiedIndex(null), 2000);
|
|
|
};
|
|
|
- console.log(content);
|
|
|
|
|
|
return (
|
|
|
- <ReactMarkdown
|
|
|
- remarkPlugins={[remarkGfm]}
|
|
|
- rehypePlugins={[rehypeRaw]}
|
|
|
- components={{
|
|
|
- code({ node, className, children, ...props }) {
|
|
|
- const match = /language-(\w+)/.exec(className || "");
|
|
|
- const code = String(children).replace(/\n$/, "");
|
|
|
- const language = match ? match[1] : "";
|
|
|
- if (match) {
|
|
|
- return (
|
|
|
- <div className="rounded-md overflow-hidden mb-4">
|
|
|
- <CodeHeader
|
|
|
- language={language}
|
|
|
- onCopy={() =>
|
|
|
- handleCopy(code, node?.position?.start.line ?? 0)
|
|
|
- }
|
|
|
- copied={copiedIndex === node?.position?.start.line}
|
|
|
- />
|
|
|
- <div className="max-w-full overflow-x-auto">
|
|
|
- <SyntaxHighlighter
|
|
|
- style={vscDarkPlus}
|
|
|
+ <div className="markdown-body">
|
|
|
+ <ReactMarkdown
|
|
|
+ remarkPlugins={[remarkGfm]}
|
|
|
+ rehypePlugins={[rehypeRaw]}
|
|
|
+ components={{
|
|
|
+ code({ node, className, children, ...props }) {
|
|
|
+ const match = /language-(\w+)/.exec(className || "");
|
|
|
+ const code = String(children).replace(/\n$/, "");
|
|
|
+ const language = match ? match[1] : "";
|
|
|
+ if (match) {
|
|
|
+ return (
|
|
|
+ <div className="rounded-md overflow-hidden mb-4">
|
|
|
+ <CodeHeader
|
|
|
language={language}
|
|
|
- PreTag="div"
|
|
|
- {...props}
|
|
|
- customStyle={{
|
|
|
- margin: 0,
|
|
|
- borderTopLeftRadius: 0,
|
|
|
- borderTopRightRadius: 0,
|
|
|
- }}
|
|
|
- >
|
|
|
- {code}
|
|
|
- </SyntaxHighlighter>
|
|
|
+ onCopy={() =>
|
|
|
+ handleCopy(code, node?.position?.start.line ?? 0)
|
|
|
+ }
|
|
|
+ copied={copiedIndex === node?.position?.start.line}
|
|
|
+ />
|
|
|
+ <div className="max-w-full overflow-x-auto">
|
|
|
+ <SyntaxHighlighter
|
|
|
+ style={vscDarkPlus}
|
|
|
+ language={language}
|
|
|
+ PreTag="div"
|
|
|
+ {...props}
|
|
|
+ customStyle={{
|
|
|
+ margin: 0,
|
|
|
+ borderTopLeftRadius: 0,
|
|
|
+ borderTopRightRadius: 0,
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {code}
|
|
|
+ </SyntaxHighlighter>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return (
|
|
|
+ <code className={className} {...props}>
|
|
|
+ {children}
|
|
|
+ </code>
|
|
|
);
|
|
|
- }
|
|
|
- return (
|
|
|
- <code className={className} {...props}>
|
|
|
- {children}
|
|
|
- </code>
|
|
|
- );
|
|
|
- },
|
|
|
- }}
|
|
|
- >
|
|
|
- {content}
|
|
|
- </ReactMarkdown>
|
|
|
+ },
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {content}
|
|
|
+ </ReactMarkdown>
|
|
|
+ </div>
|
|
|
);
|
|
|
};
|
|
|
|