|
3 | 3 | import React, { useState } from 'react'; |
4 | 4 | import ReactMarkdown from 'react-markdown'; |
5 | 5 | import remarkGfm from 'remark-gfm'; |
6 | | -import rehypeRaw from 'rehype-raw'; // Add this |
| 6 | +import rehypeRaw from 'rehype-raw'; |
| 7 | +import rehypeSanitize from 'rehype-sanitize'; |
7 | 8 | import { Copy, Check, FileCode, } from 'lucide-react'; |
8 | 9 |
|
9 | 10 | export const MarkdownPreview = ({ content }: { content: string }) => { |
10 | 11 | const [view, setView] = useState<'code' | 'preview'>('preview'); |
11 | 12 | const [copied, setCopied] = useState(false); |
12 | 13 |
|
13 | 14 | const handleCopy = async () => { |
14 | | - await navigator.clipboard.writeText(content); |
15 | | - setCopied(true); |
16 | | - setTimeout(() => setCopied(false), 2000); |
| 15 | + try { |
| 16 | + await navigator.clipboard.writeText(content); |
| 17 | + setCopied(true); |
| 18 | + setTimeout(() => setCopied(false), 2000); |
| 19 | + } catch (error) { |
| 20 | + console.error('Failed to copy to clipboard:', error); |
| 21 | + setCopied(false); |
| 22 | + } |
17 | 23 | }; |
18 | 24 |
|
19 | 25 | if (!content) return null; |
@@ -70,7 +76,7 @@ export const MarkdownPreview = ({ content }: { content: string }) => { |
70 | 76 | <div className="preview-content"> |
71 | 77 | <ReactMarkdown |
72 | 78 | remarkPlugins={[remarkGfm]} |
73 | | - rehypePlugins={[rehypeRaw]} |
| 79 | + rehypePlugins={[rehypeRaw, rehypeSanitize]} |
74 | 80 | > |
75 | 81 | {content} |
76 | 82 | </ReactMarkdown> |
|
0 commit comments