'use client'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import rehypeHighlight from 'rehype-highlight'; import rehypeRaw from 'rehype-raw'; import type { Draft } from '@/lib/db/draft-service'; interface DraftContentProps { draft: Draft; } /** * DraftContent Component - Markdown renderer for draft content * * Renders draft content with: * - Merriweather serif font for "published" feel * - Markdown parsing with GFM support * - Syntax highlighting for code blocks * - Tag display * - Generous whitespace for comfortable reading */ export function DraftContent({ draft }: DraftContentProps) { // Strip the first heading from content if it matches the title const processedContent = (() => { const lines = draft.content.split('\n'); const firstLine = lines[0]?.trim() || ''; // Check if first line is a heading that matches the title const headingMatch = firstLine.match(/^#+\s*(.+)$/); if (headingMatch) { const headingText = headingMatch[1].trim(); if (headingText.toLowerCase() === draft.title.toLowerCase()) { // Remove the first line (and any immediate blank lines after it) let startIndex = 1; while (startIndex < lines.length && lines[startIndex].trim() === '') { startIndex++; } return lines.slice(startIndex).join('\n'); } } return draft.content; })(); return (
{/* Title - using Merriweather serif font */}

{draft.title}

{/* Body content - Markdown with prose styling */}
(

), h2: ({ node, ...props }) => (

), h3: ({ node, ...props }) => (

), // Paragraph styling p: ({ node, ...props }) => (

), // Code blocks code: ({ node, inline, className, children, ...props }: any) => { if (inline) { return ( {children} ); } return ( {children} ); }, // Pre tags pre: ({ node, ...props }) => (

            ),
            // Links
            a: ({ node, ...props }) => (
              
            ),
            // Lists
            ul: ({ node, ...props }) => (
              
    ), ol: ({ node, ...props }) => (
      ), // Blockquotes blockquote: ({ node, ...props }) => (
      ), }} > {processedContent}

{/* Tags section */} {draft.tags && draft.tags.length > 0 && (
{draft.tags.map((tag) => ( #{tag} ))}
)}
); }