diff --git a/src/components/Generator/MarkdownPreview.tsx b/src/components/Generator/MarkdownPreview.tsx index 669d2d4..3c07a1e 100644 --- a/src/components/Generator/MarkdownPreview.tsx +++ b/src/components/Generator/MarkdownPreview.tsx @@ -5,7 +5,7 @@ import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import rehypeRaw from "rehype-raw"; import rehypeSanitize from "rehype-sanitize"; -import { Copy, Check, FileCode } from "lucide-react"; +import { Copy, Check, Download, FileCode } from "lucide-react"; export const MarkdownPreview = ({ content }: { content: string }) => { const [view, setView] = useState<"code" | "preview">("preview"); @@ -22,6 +22,18 @@ export const MarkdownPreview = ({ content }: { content: string }) => { } }; + const handleDownload = () => { + const blob = new Blob([content], { type: "text/markdown;charset=utf-8" }); + const url = URL.createObjectURL(blob); + const link = document.createElement("a"); + link.href = url; + link.download = "README.md"; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(url); + }; + if (!content) return null; return ( @@ -120,13 +132,22 @@ export const MarkdownPreview = ({ content }: { content: string }) => { - +