'use client'; import hljs from 'highlight.js'; import { toPng } from 'html-to-image'; import { AlertCircle, Loader2 } from 'lucide-react'; import { marked } from 'marked'; import React, { useRef, useState } from 'react'; import 'highlight.js/styles/github.css'; marked.setOptions({ highlight: function (code, lang) { if (lang && hljs.getLanguage(lang)) { return hljs.highlight(code, { language: lang }).value; } return code; }, }); export default function Home() { const [file, setFile] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [preview, setPreview] = useState(''); const previewRef = useRef(null); const handleFileChange = async (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (!file) return; try { const content = await file.text(); const htmlContent = marked(content); setPreview(htmlContent); setFile(file); setError(null); } catch (err) { setError('Failed to read file'); console.error(err); } }; const handleConvert = async () => { if (!previewRef.current) return; setLoading(true); setError(null); try { const dataUrl = await toPng(previewRef.current, { quality: 1.0, pixelRatio: 2, style: { margin: '20px' }, }); const link = document.createElement('a'); link.download = `${file?.name.replace('.md', '')}.png` || 'markdown.png'; link.href = dataUrl; link.click(); } catch (err) { setError('Failed to convert to image.'); console.error(err); } finally { setLoading(false); } }; return (

Markdown to PNG Converter

Convert your Markdown files into PNG images with GitHub-style formatting.

How to use:

  1. Upload your Markdown (.md) file using the button below
  2. Preview your formatted Markdown
  3. Click "Convert to PNG" to download your image
{error && (

{error}

)}
{preview && (

Preview

)}
); }