"use client"; import React, { useState } from "react"; import Editor from "@monaco-editor/react"; import { html_beautify } from "js-beautify"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { FileCode, Copy, RotateCcw, ArrowRight } from "lucide-react"; import { toast } from "sonner"; import { useTheme } from "next-themes"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Label } from "@/components/ui/label"; export default function HtmlFormatterPage() { const { theme } = useTheme(); const [input, setInput] = useState(""); const [output, setOutput] = useState(""); const [indentSize, setIndentSize] = useState("2"); const [wrapLineLength, setWrapLineLength] = useState("80"); const handleFormat = () => { if (!input.trim()) return; try { const formatted = html_beautify(input, { indent_size: parseInt(indentSize), wrap_line_length: parseInt(wrapLineLength), preserve_newlines: true, indent_inner_html: true, }); setOutput(formatted); toast.success("HTML 格式化成功"); } catch { toast.error("HTML 格式化失败"); } }; const copyToClipboard = async (text: string) => { try { await navigator.clipboard.writeText(text); toast.success("已复制到剪贴板"); } catch { toast.error("复制失败"); } }; return (

HTML 格式化

美化和清理 HTML 代码

{/* Options */}
{/* Input */} 输入 HTML
setInput(value || "")} options={{ minimap: { enabled: false }, fontSize: 14, wordWrap: "on" }} />
{/* Output */} 结果
); }