"use client";
import { useState } from "react";
import { Card, CardContent, CardHeader, CardTitle } from "@hanzo/ui/primitives/card";
import { Button } from "@hanzo/ui/primitives/button";
import { Textarea } from "@hanzo/ui/primitives/textarea";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@hanzo/ui/primitives/tabs";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@hanzo/ui/primitives/select";
import { Separator } from "@hanzo/ui/primitives/separator";
import { ScrollArea } from "@hanzo/ui/primitives/scroll-area";
import {
Bold,
Italic,
Link,
List,
ListOrdered,
Quote,
Code,
Heading1,
Heading2,
Image,
Table,
Download,
Copy,
Eye,
FileText,
Save
} from "lucide-react";
export default function MarkdownEditor() {
const [markdown, setMarkdown] = useState(`# Welcome to Hanzo Markdown Editor
Built with **@hanzo/ui components** for a seamless writing experience.
## Features
- 🚀 **Live Preview** - See your changes in real-time
- 🎨 **Syntax Highlighting** - Beautiful code blocks
- 📱 **Responsive Design** - Works on all devices
- 🌙 **Dark Mode Support** - Easy on the eyes
## Code Example
\`\`\`typescript
import { Card } from "@hanzo/ui/primitives/card";
import { Button } from "@hanzo/ui/primitives/button";
export function MyComponent() {
return (
);
}
\`\`\`
## Lists
### Unordered List
- First item
- Second item
- Third item
### Ordered List
1. Step one
2. Step two
3. Step three
## Blockquote
> "The best way to predict the future is to invent it."
> - Alan Kay
## Table
| Feature | Status | Priority |
|---------|--------|----------|
| Live Preview | ✅ Complete | High |
| Export Options | ✅ Complete | Medium |
| Collaboration | 🚧 In Progress | Low |
---
Start writing your content above!
`);
const [viewMode, setViewMode] = useState("split");
const insertMarkdown = (before: string, after: string = "") => {
const textarea = document.getElementById("markdown-input") as HTMLTextAreaElement;
if (!textarea) return;
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
const selectedText = markdown.substring(start, end);
const newText = before + selectedText + after;
const newMarkdown =
markdown.substring(0, start) +
newText +
markdown.substring(end);
setMarkdown(newMarkdown);
// Restore cursor position
setTimeout(() => {
textarea.focus();
textarea.setSelectionRange(
start + before.length,
start + before.length + selectedText.length
);
}, 0);
};
const renderMarkdown = (text: string) => {
// Simple markdown to HTML conversion (in production, use a proper markdown parser)
let html = text
.replace(/^### (.*$)/gim, '
$1
')
.replace(/^## (.*$)/gim, '$1
')
.replace(/^# (.*$)/gim, '$1
')
.replace(/\*\*(.+?)\*\*/g, '$1')
.replace(/\*(.+?)\*/g, '$1')
.replace(/```(\w+)?\n([\s\S]*?)```/g, '$2
')
.replace(/`(.+?)`/g, '$1')
.replace(/^> (.*$)/gim, '$1
')
.replace(/^- (.*$)/gim, '• $1')
.replace(/^\d+\. (.*$)/gim, '$1')
.replace(/\[(.+?)\]\((.+?)\)/g, '$1')
.replace(/\n\n/g, '')
.replace(/^---$/gim, '
');
return ``;
};
return (
{/* Header Toolbar */}
Markdown Editor
{/* Editor Area */}
{/* Editor Panel */}
{(viewMode === "edit" || viewMode === "split") && (
)}
{/* Preview Panel */}
{(viewMode === "preview" || viewMode === "split") && (
)}
{/* Status Bar */}
{markdown.length} characters
{markdown.split(/\s+/).filter(w => w).length} words
{markdown.split("\n").length} lines
Markdown
);
}