Skip to content

fix: keep local images through folder import and allow remote markdown images - #697

Open
chang30519-art wants to merge 1 commit into
nashsu:mainfrom
chang30519-art:fix/markdown-image-pipeline
Open

fix: keep local images through folder import and allow remote markdown images#697
chang30519-art wants to merge 1 commit into
nashsu:mainfrom
chang30519-art:fix/markdown-image-pipeline

Conversation

@chang30519-art

Copy link
Copy Markdown

Summary

Two small fixes for markdown image handling found while importing a folder of .md notes with local images:

1. Folder import dropped every local image file

importSourceFolder filters every file through isPathAllowedBySourceWatch, and the default includeExtensions whitelist (source-watch-defaults.json) only contains document formats — no image extensions at all. After a folder import:

  • the .md files land in raw/sources/<folder>/...
  • but sibling image files are skipped as excluded

Consequences:

  • Preview broken: relative refs like ![](images/a.png) resolve (Obsidian-style, via resolveMarkdownImageSrc) to <project>/raw/sources/<folder>/images/a.png, which was never copied.
  • Ingest-time extraction gets nothing: extractAndSaveMarkdownImages resolves refs against the same missing paths (fileExists → skip), so there are never any images to hand to the vision-caption pipeline.

This adds the exact extensions already accepted by findLocalMarkdownImageRefs (png/jpg/jpeg/gif/webp/bmp/tif/tiff/svg) to the default whitelist. Image files stay resource-only — isIngestableSourcePath still keeps them out of the ingest queue.

2. CSP blocked remote markdown images

The resolver passes http(s):// image URLs through unchanged, but the Tauri CSP only allowed img-src 'self' asset: blob: data: — so every web-embedded image (![](https://...)) was refused by the webview and rendered as broken. (connect-src already allowed https: http:, which is why everything else worked.)

Adds https: http: to img-src. This matches what Obsidian/Typora-style markdown editors do; local file access remains restricted by 'self' + the asset protocol scope.

Testing

  • vitest run src/lib/source-watch-config.test.ts src/lib/source-lifecycle.test.ts src/lib/extract-source-images.test.ts — 28 passed
  • vitest run src/lib/project-file-sync.test.ts src/lib/scheduled-import.test.ts src/lib/ingest-queue.test.ts src/components/sources/sources-view.test.ts — 108 passed

Manual verification of the CSP change requires a rebuild (npm run tauri build).

…n images

Folder imports dropped every image file because the default
source-watch includeExtensions whitelist only contained document
formats. An imported .md therefore referenced sibling images that were
never copied into raw/sources, so both the source preview and the
ingest-time extractAndSaveMarkdownImages lookup failed silently.

Add the extensions already accepted by findLocalMarkdownImageRefs
(png/jpg/jpeg/gif/webp/bmp/tif/tiff/svg) to the default whitelist.
Image files are resource-only: isIngestableSourcePath still keeps them
out of the ingest queue.

Also relax img-src in the Tauri CSP to include https:/http:. The
markdown image resolver passes remote URLs through unchanged, but the
webview CSP blocked every <img src=https://...>, so web-embedded
images never rendered in previews.
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.

1 participant