LightweightDarkModeFirstMarkdownEditor
## CONTEXT You are an expert frontend engineer specialising in browser-based cod
ChatGPTCode & Tech
1,069 words · free to use
## CONTEXT You are an expert frontend engineer specialising in browser-based code and text editors. You are building a **lightweight, dark-mode-first markdown editor** that runs entirely in the browser (no backend required) using vanilla JavaScript, HTML, and CSS — or a minimal framework if strongly justified. The editor must feel snappy, have zero unnecessary dependencies, and load in under 2 seconds on a mid-range device. The project must be structured so that every major feature (syntax highlighting, theming, custom highlighter logic) is a discrete, replaceable module. ## OBJECTIVE Design and implement a complete, production-quality, browser-based editor with ALL of the following capabilities: 1. **Dark-mode-first UI** with an explicit toggle between a polished dark mode (default) and a polished light mode. Both modes must be fully styled — no half-finished light theme. 2. **Multi-language support** for: Markdown, YAML, HTML, CSS, JavaScript, and Plain Text. The user can select the active language from a dropdown or tab bar. 3. **Pre-made syntax highlighting themes** — supply at least THREE distinct built-in themes (e.g., "Midnight" dark, "Solarized" light, "Dracula" dark). Each theme must define token colors for every supported language. 4. **Custom syntax highlighter builder** — a dedicated UI panel where the user can: - Define named token types (keyword, string, comment, operator, number, tag, attribute, variable, etc.) - Assign regex patterns to each token type - Pick a foreground color, background color, font-weight, and font-style per token - Preview the result live against the current editor content - Export the custom theme as a JSON file - Import a previously exported JSON theme file 5. **Toolbar** with: New, Open (file), Save (download), Copy All, Word Count, Line Count, Toggle Word Wrap, Toggle Line Numbers, Language Selector, Theme Selector, Dark/Light Mode Toggle. 6. **Editor core** features: line numbers, word wrap toggle, find-and-replace (Ctrl+H), go-to-line (Ctrl+G), auto-indent, bracket matching, undo/redo (native + extended history), and smooth scrolling. 7. **Live Markdown preview** pane (side-by-side or toggleable) that renders sanitized HTML from the Markdown source when the language is set to Markdown. 8. **Accessibility**: keyboard navigable, ARIA labels, sufficient color contrast in both modes (WCAG AA minimum). ## STYLE - Code must be clean, modular, and commented at the module boundary level. - File structure should follow a clear separation: `index.html`, `css/themes.css`, `css/editor.css`, `js/editor.js`, `js/highlighter.js`, `js/languages/[lang].js`, `js/themeEngine.js`, `js/customHighlighterUI.js`, `js/markdownPreview.js`, `js/toolbar.js`. - Dark mode palette anchor: background `#1a1a2e`, surface `#16213e`, accent `#e94560`, text `#eaeaea`. - Light mode palette anchor: background `#f5f5f0`, surface `#ffffff`, accent `#0f3460`, text `#1a1a2e`. - Typography: monospace font for the editor (JetBrains Mono or system monospace fallback), sans-serif for UI chrome. - Animations: subtle only — mode toggle crossfade ≤ 200 ms, panel slide ≤ 150 ms. ## TASK Deliver the following in sequence: ### TASK 1 — Project Scaffold & Core Editor - Produce the full `index.html` with all script/style references, the editor `<textarea>` or `contenteditable` div, toolbar skeleton, preview pane skeleton, and custom highlighter panel skeleton. - Produce `css/editor.css`: complete styling for the editor area, line numbers, scrollbars, selection highlight, cursor, and both dark/light mode variants using CSS custom properties. - Produce `js/editor.js`: initialise the editor, wire up keyboard shortcuts, implement line numbers, word wrap toggle, find-and-replace modal, go-to-line modal, undo/redo stack (min 200 steps), and auto-indent logic. ### TASK 2 — Syntax Highlighting Engine - Produce `js/highlighter.js`: a tokenizer engine that accepts (a) a language definition object and (b) a theme object, then returns decorated HTML spans. It must handle overlapping token priorities gracefully (longest-match-first wins). - Produce `js/languages/markdown.js`, `js/languages/yaml.js`, `js/languages/html.js`, `js/languages/css.js`, `js/languages/javascript.js`, `js/languages/plaintext.js` — each exporting a language definition object with named token rules (regex + token type). - Produce `js/themeEngine.js`: manages loading, switching, and persisting (localStorage) the active theme; exposes `setTheme(themeObj)`, `getTheme()`, `listThemes()`, `registerTheme(name, themeObj)`. - Produce `css/themes.css`: the three built-in themes (Midnight, Solarized, Dracula) expressed as CSS custom property blocks, scoped to `[data-theme="midnight"]`, `[data-theme="solarized"]`, `[data-theme="dracula"]`. ### TASK 3 — Custom Syntax Highlighter UI - Produce `js/customHighlighterUI.js`: full implementation of the custom highlighter builder panel including: - Dynamic token row add/remove - Inline color pickers (native `<input type="color">`) - Regex input with real-time validation (red border on invalid regex) - Live preview updating within 300 ms of any change (debounced) - Export to JSON (`Blob` + `URL.createObjectURL`) - Import from JSON (file input → parse → validate schema → load) - "Apply as Active Theme" button that calls `themeEngine.registerTheme` and `themeEngine.setTheme` ### TASK 4 — Markdown Preview & Toolbar - Produce `js/markdownPreview.js`: a zero-dependency Markdown-to-HTML renderer supporting headings, bold, italic, inline code, code fences (with language label), blockquotes, ordered/unordered lists, horizontal rules, links, images, and tables. Output must be sanitized (strip `<script>`, `javascript:` hrefs, event handler attributes). - Produce `js/toolbar.js`: wire up every toolbar button and dropdown described in the Objective, persist user preferences (word wrap, line numbers, language, theme, dark/light mode) to localStorage. ### TASK 5 — Integration, Testing Checklist & README - Provide a step-by-step integration guide confirming how all modules connect. - Provide a manual QA checklist covering: mode toggle, all six languages, all three themes, custom theme round-trip (build → export → reimport → apply), find-and-replace, markdown preview parity, keyboard shortcuts, and accessibility tab-order. - Provide a `README.md` with setup instructions (open `index.html` in browser — no build step), feature list, custom theme JSON schema documentation, and contribution guidelines. ## ACTION - Work through TASK 1 through TASK 5 in order. - For each task, output the FULL file contents — no truncation, no placeholders like `// ... rest of code`. Every function must be implemented. - Before each file, print a comment header: `// FILE: path/to/filename.ext` so files are easy to identify and extract. - Where a design decision has multiple valid approaches, briefly note the chosen approach and why in a `// DESIGN:` comment at the top of the relevant function. - Validate that CSS custom properties are used consistently and never hard-code a color value outside of `css/themes.css` and `css/editor.css`. - Ensure the custom highlighter JSON schema is documented inline via a `SCHEMA` constant in `js/customHighlighterUI.js`. ## RESULT The final deliverable is a complete, copy-paste-deployable set of source files that, when placed in the same directory and opened via `index.html` in any modern browser (Chrome 110+, Firefox 110+, Safari 16+), produce a fully functional dark-mode-first markdown editor meeting every requirement listed above. The editor must work offline with no CDN calls — all assets self-contained. Confirm completion by printing a `✅ DELIVERY COMPLETE` summary listing every file delivered and its line count.
How to use this prompt
- Copy the prompt with the button above.
- Paste it into ChatGPT and send it. It also works in other AI chat tools.
- Not quite right? Reply with what to change — "shorter", "more casual", "give me 3 options" — instead of starting over.