"use client"; import React, { useState } from "react"; import Editor from "@monaco-editor/react"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { FileText, Download, Copy, Eye, Edit3, Trash2 } from "lucide-react"; import { toast } from "sonner"; import { useTheme } from "next-themes"; const DEFAULT_MARKDOWN = `# Welcome to Markdown Editor This is a **live preview** editor. You can write your markdown on the left (or top), and see the result instantly. ## Features - [x] GFM Support (Tables, Tasks, Strikethrough) - [x] Syntax Highlighting - [x] Vertical/Horizontal Layout (Responsive) ### Code Example \`\`\`javascript function hello() { console.log("Hello World!"); } \`\`\` ### Table Example | Item | Price | Quantity | |:-----|:-----:|:---------| | Apple| $1.00 | 5 | | Pear | $2.00 | 10 | > "The best way to predict the future is to create it." `; export default function MarkdownPage() { const { theme } = useTheme(); const [markdown, setMarkdown] = useState(DEFAULT_MARKDOWN); const copyToClipboard = async () => { try { await navigator.clipboard.writeText(markdown); toast.success("Markdown 已复制"); } catch { toast.error("复制失败"); } }; const downloadMarkdown = () => { const blob = new Blob([markdown], { type: "text/markdown" }); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = "document.md"; a.click(); URL.revokeObjectURL(url); toast.success("下载已开始"); }; return (

Markdown 编辑器

实时预览、GFM 支持、所见即所得

{/* Editor */} 编辑 setMarkdown(value || "")} options={{ minimap: { enabled: false }, fontSize: 14, wordWrap: "on", padding: { top: 16 } }} /> {/* Preview */} 预览 {markdown}
); }