feat: render local PNG/image files in WYSIWYG editor#9
Merged
Conversation
Local images referenced with relative paths (e.g. `assets/photo.png`) now render correctly in the Tiptap editor. The webview can't resolve paths relative to the document directory, so we convert them to Tauri asset protocol URLs (`http://asset.localhost/...`) on load and strip them back to relative paths on save. Changes: - Enable Tauri `protocol-asset` feature and asset protocol scope - Add `imagePathResolver.ts` utility (resolve/unresolve image paths) - Wrap markdownToHtml/htmlToMarkdown in Editor.vue with path resolution - Resolve paths in GdownImage drag/drop/paste and input rule handlers - Add `convertFileSrc` to test setup mock - 33 new tests for image path resolution Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
) now render correctly in the Tiptap WYSIWYG editorconvertFileSrc+ asset protocol to convert relative filesystem paths to URLs the webview can loadWhat changed
src-tauri/tauri.conf.json— Enable asset protocol with wildcard scopesrc-tauri/Cargo.toml— Addprotocol-assetfeature to Tauri dependencysrc/utils/imagePathResolver.ts(new) —resolveImagePaths/unresolveImagePaths/resolveRelativeSrcutilitiessrc/components/Editor.vue— WrapmarkdownToHtml/htmlToMarkdowncalls with path resolution viamdToHtml/htmlToMdhelperssrc/extensions/GdownImage.ts— Resolve relative paths in drag-drop and paste handlerssrc/extensions/MarkdownImageInputRule.ts— Resolve relative paths wheninput rule firessrc/__tests__/setup.ts— AddconvertFileSrcmock to Tauri APIsrc/__tests__/utils/imagePathResolver.test.ts(new) — 33 tests covering resolve, unresolve, round-trip, and edge casesHow it works
markdownToHtml()output is post-processed — relative<img src="assets/...">becomes<img src="http://asset.localhost/absolute/path/..." data-original-src="assets/...">getHTML()output is post-processed — asset URLs restored to relative paths viadata-original-srcor prefix strippingconvertFileSrcTest plan
— image renders in WYSIWYG mode— image renders via input rule🤖 Generated with Claude Code