From e27bb64c7a4e764dfc89a1196f31512a8d4dd795 Mon Sep 17 00:00:00 2001 From: ddshi <8811906+ddshi@user.noreply.gitee.com> Date: Sat, 28 Feb 2026 11:39:40 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=E5=AD=90=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=EF=BC=88=E5=86=9C=E5=8E=86=E5=92=8CAI=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 --- src/components/note/NoteEditor.tsx | 366 ++++++++++++----------------- src/index.css | 108 +++++++++ 2 files changed, 264 insertions(+), 210 deletions(-) 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