diff --git a/src/components/note/NoteEditor.tsx b/src/components/note/NoteEditor.tsx index 0c87ed0..7f01c5c 100644 --- a/src/components/note/NoteEditor.tsx +++ b/src/components/note/NoteEditor.tsx @@ -1,25 +1,85 @@ import { useState, useEffect, useCallback, useRef } from 'react'; import { Paper, - Textarea, Group, Text, Stack, - Button, Box, } from '@mantine/core'; import { useDebouncedValue } from '@mantine/hooks'; -import ReactMarkdown from 'react-markdown'; -import remarkGfm from 'remark-gfm'; -import rehypeSanitize from 'rehype-sanitize'; -import { IconDeviceFloppy } from '@tabler/icons-react'; import { useAppStore } from '../../stores'; interface NoteEditorProps { onSave?: () => void; } -type ViewMode = 'edit' | 'preview'; +// Simple Markdown to HTML converter +function parseMarkdown(text: string): string { + if (!text) return ''; + + let html = text; + + // Escape HTML first (but preserve our line breaks) + html = html.replace(/&/g, '&').replace(//g, '>'); + + // Code blocks (must be before inline code) + html = html.replace(/```([\s\S]*?)```/g, '
$1
'); + + // Inline code + html = html.replace(/`([^`]+)`/g, '$1'); + + // Headers + html = html.replace(/^######\s+(.*)$/gm, '
$1
'); + html = html.replace(/^#####\s+(.*)$/gm, '
$1
'); + html = html.replace(/^####\s+(.*)$/gm, '

$1

'); + html = html.replace(/^###\s+(.*)$/gm, '

$1

'); + html = html.replace(/^##\s+(.*)$/gm, '

$1

'); + html = html.replace(/^#\s+(.*)$/gm, '

$1

'); + + // Bold (**text** or __text__) + html = html.replace(/\*\*([^*]+)\*\*/g, '$1'); + html = html.replace(/__([^_]+)__/g, '$1'); + + // Italic (*text* or _text_) + html = html.replace(/\*([^*]+)\*/g, '$1'); + html = html.replace(/_([^_]+)_/g, '$1'); + + // Strikethrough (~~text~~) + html = html.replace(/~~([^~]+)~~/g, '$1'); + + // Links [text](url) + html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'); + + // Unordered lists (- item or * item) + html = html.replace(/^[-*]\s+(.*)$/gm, '
  • $1
  • '); + // Wrap consecutive
  • elements in