feat: rich paste#1254
Merged
Merged
Conversation
Paste HTML content (from browsers, Notion, Google Docs, etc.) directly into the editor — headings, links, images, lists, tables, task lists, code blocks and inline formatting are all converted to Markdown via Turndown + GFM plugin. A TDD test suite (37 tests) covers the full conversion surface. Plain-text paste is available via Shift+Ctrl/Cmd+V and both modes are accessible from two new toolbar buttons (desktop + mobile dropdown). Also fixes: paste over selection now replaces instead of inserting at anchor; async clipboard handlers guard against destroyed view; auto-save debounce is flushed on navigation instead of silently dropped; page transitions are smoothed with a 130ms fade animation.
…sset bloat - Guard the CodeMirror Shift-Mod-v paste and the toolbar pasteRich/pastePlain actions against the editor view being destroyed or swapped to a different page while a clipboard read is pending - Upload inline base64 images from pasted HTML through the real asset pipeline instead of inlining raw base64 into markdown - Scope NBSP normalization in htmlToMarkdown to prose, leaving fenced/inline code content untouched - Surface autosave errors (incl. version conflicts) from the unmount flush instead of swallowing them, and retry once if the store's save mutex blocked it - Reuse the clipboard items already fetched for pasteRich's plain-text fallback instead of a second clipboard read - Add toast feedback and data-testid to the paste toolbar buttons - Adjust TOC side panel spacing/scroll CSS
Contributor
There was a problem hiding this comment.
Pull request overview
Adds “rich paste” support to the LeafWiki markdown editor, converting pasted HTML (e.g., from Google Docs/Word/web pages) into Markdown and handling embedded images safely by uploading inline data-URI images as assets.
Changes:
- Add HTML→Markdown conversion (Turndown + GFM plugin) with special handling for Google Docs/Word quirks.
- Add rich/plain paste actions in the toolbar and editor integrations (including data-URI image upload/rewrites).
- Improve auto-save behavior by flushing pending debounced saves on unmount to reduce lost edits.
Reviewed changes
Copilot reviewed 11 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| ui/leafwiki-ui/src/vite-env.d.ts | Adds ambient typings for turndown-plugin-gfm. |
| ui/leafwiki-ui/src/locales/en/editor.json | Adds i18n strings for rich/plain paste UI and clipboard errors. |
| ui/leafwiki-ui/src/index.css | Minor layout adjustments (flex min-width, tree toolbar spacing, sidebar overflow changes). |
| ui/leafwiki-ui/src/features/editor/useAutoSave.ts | Flush pending debounced auto-save on unmount and surface errors consistently. |
| ui/leafwiki-ui/src/features/editor/pasteImageUpload.ts | Uploads inline data-URI images and rewrites markdown references to uploaded asset URLs. |
| ui/leafwiki-ui/src/features/editor/pasteImageUpload.test.ts | Tests for inline data-URI image upload/rewriting behavior. |
| ui/leafwiki-ui/src/features/editor/MarkdownToolbar.tsx | Adds toolbar buttons and mobile menu items for rich/plain paste. |
| ui/leafwiki-ui/src/features/editor/MarkdownEditor.tsx | Implements imperative pasteRich/pastePlain methods using Clipboard APIs + HTML→MD + inline image upload. |
| ui/leafwiki-ui/src/features/editor/MarkdownCodeEditor.tsx | Adds HTML paste handling in CodeMirror + plain-paste shortcut and inline image upload integration. |
| ui/leafwiki-ui/src/features/editor/htmlToMarkdown.ts | Introduces Turndown-based HTML→Markdown converter with normalization rules. |
| ui/leafwiki-ui/src/features/editor/htmlToMarkdown.test.ts | Comprehensive test coverage for HTML→Markdown conversions and edge cases. |
| ui/leafwiki-ui/package.json | Adds turndown, turndown-plugin-gfm, and @types/turndown dependencies. |
| ui/leafwiki-ui/package-lock.json | Locks newly added dependencies. |
Files not reviewed (1)
- ui/leafwiki-ui/package-lock.json: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.