CONTEXT:
You are an expert frontend developer specializing in building rich text editor applications using vanilla HTML5, CSS3, and JavaScript (no frameworks unless specified). You have deep expertise in markdown parsing libraries (marked.js, markdown-it), syntax highlighting (highlight.js, Prism.js), LaTeX rendering (MathJax, KaTeX), PDF generation (jsPDF, html2pdf.js), and modern browser APIs including localStorage, IndexedDB, and the File System Access API. The application must be entirely self-contained, production-ready, and run in any modern browser without a backend.
OBJECTIVE:
Build a complete, feature-rich Markdown Notes Application as a single HTML file (or organized multi-file structure) with the following exhaustive feature set:
1. SPLIT-SCREEN EDITOR:
- Resizable split pane with draggable divider (mouse and touch support)
- Left pane: CodeMirror 6 or Monaco Editor-powered markdown editor with syntax highlighting, line numbers, bracket matching, auto-indent, and vim/emacs keybinding options
- Right pane: Live rendered HTML preview that updates in real-time (debounced 300ms) as user types
- Three view modes: Editor Only, Split View, Preview Only (keyboard shortcuts: Ctrl+1, Ctrl+2, Ctrl+3)
- Synchronized scrolling between editor and preview panes
- Editor toolbar with buttons for: Bold, Italic, Strikethrough, Heading (H1-H6), Blockquote, Code inline, Code block, Link, Image, Table generator (with row/col picker), Horizontal rule, Ordered list, Unordered list, Task list, LaTeX inline, LaTeX block
2. MARKDOWN RENDERING ENGINE:
- Use markdown-it with full CommonMark compliance plus extensions
- Tables: Full GFM table support with alignment, sortable columns in preview, responsive wrapping
- Code blocks: Syntax highlighting via highlight.js for 50+ languages, with language label badge, one-click copy button, and optional line numbers
- LaTeX/Math: Inline math ($...$) and block math ($$...$$) rendered via KaTeX for performance
- Checkboxes: Clickable task list items that update source markdown
- Footnotes, definition lists, abbreviations, superscript, subscript support
- Mermaid.js diagram rendering (flowcharts, sequence diagrams, Gantt charts)
- Emoji shortcode support (:smile:, etc.)
- Smart typography (curly quotes, em-dashes, ellipses)
- Custom container blocks (:::tip, :::warning, :::danger)
- Table of contents auto-generation from headings with smooth scroll
3. HIERARCHICAL ORGANIZATION:
- Sidebar panel with resizable width
- Nested categories/folders with unlimited depth (tree structure)
- Drag-and-drop to reorganize notes and folders
- Context menu (right-click) on folders and notes: New Note, New Subfolder, Rename, Move to, Duplicate, Delete, Export
- Notes list within selected folder showing: title, preview snippet, word count, last modified date, tags
- Tag system: assign multiple color-coded tags to notes, filter notes by clicking tags
- Tag management panel: create, rename, delete, merge tags, assign colors
- Breadcrumb navigation showing current folder path
- Pinned notes section at top of notes list
- Recently modified notes quick-access section
- Favorites/starred notes collection
4. POWERFUL SEARCH:
- Global full-text search across ALL notes and folders (Ctrl+Shift+F or Cmd+Shift+F)
- Real-time search results with highlighted matching terms
- Advanced search operators: tag:tagname, folder:foldername, before:date, after:date, has:table, has:code, has:math
- Search within current note (Ctrl+F) with find and replace functionality
- Fuzzy matching with ranked relevance scoring
- Search history and saved search queries
- Filter panel: filter by tags, folders, date range, content type
5. EXPORT SYSTEM:
- Export to PDF: Using html2pdf.js or jsPDF, preserve all formatting including tables, code highlighting, and math. Options: page size (A4/Letter), margins, include/exclude TOC, header/footer with note title and page numbers
- Export to HTML: Self-contained HTML with all CSS inlined, syntax highlighting, and math rendering preserved. Option for minimal or full-featured output
- Export to Markdown: Clean .md file download of current note
- Export to plain text: Strips all markdown formatting
- Batch export: Export entire folder or all notes as ZIP archive containing individual files
- Copy to clipboard: Copy rendered HTML or plain text of current note
- Print support with print-specific CSS
6. DARK/LIGHT MODE:
- Toggle between dark and light mode (Ctrl+Shift+D)
- System preference detection via prefers-color-scheme media query with auto-mode option
- Smooth CSS transition between modes (300ms)
- Dark mode: Deep dark background (#1a1a2e or similar), syntax highlighting adapted (One Dark theme), soft contrast ratios meeting WCAG AA
- Light mode: Clean white/off-white, GitHub-light or similar code theme
- Theme persisted in localStorage
- Additional accent color picker (6-8 preset colors) that applies to UI highlights, links, active states
7. AUTO-SAVE AND VERSION HISTORY:
- Auto-save every 30 seconds and on any pause in typing (2-second debounce after last keystroke)
- Visual auto-save indicator (subtle animation in status bar: 'Saving...', 'Saved ✓', 'Save failed ✗')
- Version history per note: store last 50 versions with timestamps in IndexedDB
- Version history panel: list all saved versions with timestamp and word count diff
- Version diff view: side-by-side or unified diff display showing what changed between versions
- Restore any previous version with one click (creates new version before restoring)
- Manual save with Ctrl+S
- Crash recovery: detect unsaved changes on app load and offer to restore
- Storage usage indicator showing how much localStorage/IndexedDB space is used
8. ADDITIONAL FEATURES:
- Status bar at bottom: word count, character count, line count, cursor position (line:col), reading time estimate, current note title
- Command palette (Ctrl+Shift+P): fuzzy-searchable list of all commands and actions
- Distraction-free writing mode (F11 or button): hides sidebar and toolbar, full-screen editor, press Escape to exit
- Note statistics modal: word frequency, top keywords, readability score (Flesch-Kincaid), heading structure
- Markdown cheatsheet modal (Ctrl+?)
- Import: drag-and-drop .md/.txt files into the app to create notes, import .zip of markdown files
- Keyboard shortcuts help modal listing all shortcuts
- Undo/Redo for editor with 200-step history
- Multi-cursor editing support (if using CodeMirror)
- Settings panel: configure font size (12-24px), font family (monospace options), line height, tab size, word wrap, spell check toggle, autosave interval, max versions stored
- Inline image paste: paste image from clipboard, convert to base64 and embed in markdown
- URL auto-detection and link creation
- Notification/toast system for user feedback (save confirmations, errors, etc.)
STYLE:
- Write clean, well-commented, modular JavaScript using ES6+ classes and modules
- Use CSS custom properties (variables) for all theming values
- Follow BEM naming convention for CSS classes
- Implement proper error handling and try-catch blocks throughout
- Use async/await for all asynchronous operations
- Write defensive code that handles edge cases (empty notes, missing data, storage errors)
- Optimize for performance: virtual scrolling for large note lists, debounced renders, requestAnimationFrame for animations
- Ensure full keyboard accessibility (ARIA labels, focus management, skip links)
- Mobile-responsive design that works on tablets (stacked view replacing split-screen)
TONE:
Technical, precise, and thorough. Every feature must be fully implemented and functional. No placeholder functions, no TODO comments in delivered code. All UI interactions must feel smooth and polished.
AUDIENCE:
This prompt is being executed by an advanced AI coding assistant that will generate the complete application code. The output should be immediately deployable.
RESULT:
Deliver the complete application as:
1. index.html - Main HTML file with proper meta tags, CDN imports for: marked/markdown-it, KaTeX, highlight.js, Mermaid.js, html2pdf.js, CodeMirror (or Monaco), diff library
2. css/styles.css - All styles with CSS custom properties for theming, responsive breakpoints at 768px and 1024px, print styles
3. js/app.js - Application bootstrap and initialization
4. js/editor.js - Editor initialization, toolbar, view mode management, synchronized scrolling
5. js/renderer.js - Markdown rendering pipeline with all plugins configured
6. js/storage.js - IndexedDB wrapper class for notes, folders, versions; localStorage for settings
7. js/notes.js - Note CRUD operations, auto-save logic, version history management
8. js/folders.js - Folder/category tree management, drag-and-drop logic
9. js/tags.js - Tag system management
10. js/search.js - Full-text search engine, advanced query parser, find-and-replace
11. js/export.js - All export functionality (PDF, HTML, MD, text, ZIP)
12. js/ui.js - UI components: sidebar, status bar, command palette, modals, toasts, settings panel
13. js/theme.js - Dark/light mode, accent colors, system preference detection
For [PROJECT_NAME] application targeting [TARGET_BROWSER_SUPPORT] (e.g., 'modern browsers ES2020+'), with primary accent color [PRIMARY_ACCENT_COLOR] (e.g., '#6c63ff'), default theme [DEFAULT_THEME] ('dark' or 'light'), and maximum version history of [MAX_VERSION_HISTORY] versions per note.
Begin with index.html, then deliver each file completely without truncation. Each file must be complete and immediately functional. Include inline documentation explaining architectural decisions.