Skip to content

feat: rich paste#1254

Merged
perber merged 4 commits into
mainfrom
feat/rich-paste
Jul 5, 2026
Merged

feat: rich paste#1254
perber merged 4 commits into
mainfrom
feat/rich-paste

Conversation

@perber

@perber perber commented Jul 2, 2026

Copy link
Copy Markdown
Owner

No description provided.

perber added 2 commits July 2, 2026 18:21
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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread ui/leafwiki-ui/src/features/editor/pasteImageUpload.ts
Comment thread ui/leafwiki-ui/src/features/editor/MarkdownCodeEditor.tsx
@perber perber merged commit 1e80809 into main Jul 5, 2026
9 checks passed
@perber perber deleted the feat/rich-paste branch July 5, 2026 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants