Skip to content

feat(markdown-preview): render HTML and load local images via blob URLs#150

Merged
davideweaver merged 2 commits into
mainfrom
feat/markdown-preview-html-images
Jun 30, 2026
Merged

feat(markdown-preview): render HTML and load local images via blob URLs#150
davideweaver merged 2 commits into
mainfrom
feat/markdown-preview-html-images

Conversation

@davideweaver

Copy link
Copy Markdown
Contributor

Summary

  • Enables raw HTML rendering in the markdown preview (e.g. <img align="left">, <h3>, <br> tags in README files) via rehype-raw + rehype-sanitize with a GitHub-compatible allowlist
  • Fixes local image loading — relative/absolute paths (e.g. ./assets/logo.png) now load correctly in the Tauri webview by reading bytes through ctx.files.readBytes and serving them as blob URLs, identical to the pattern used by the image-viewer extension
  • External images (https://img.shields.io/...) pass through unchanged

New files

  • sanitize-schema.ts — GitHub sanitization schema with src protocol filter removed so local paths reach the custom <img> component
  • resolveImageSrc.ts — pure helpers (isExternalImageUrl, resolveLocalImagePath) that reuse the existing resolveFilePath from links.ts
  • resolveImageSrc.test.ts — 14 unit tests covering both helpers

Test plan

  • pnpm test — all 141 tests pass
  • pnpm --filter silo exec tsc --noEmit — no type errors
  • Open README.md in Preview mode — badge images, <img align="left">, <h3> all render (not shown as raw text)
  • Open a local .md file with a relative image path — image loads
  • Confirm <script>alert(1)</script> in a .md file stays inert

🤖 Generated with Claude Code

davideweaver and others added 2 commits June 30, 2026 11:23
Enables GitHub-style markdown rendering: raw HTML in .md files now renders
(via rehype-raw + rehype-sanitize with a GitHub-compatible allowlist), and
relative/absolute local image paths load correctly in the Tauri webview by
reading bytes through ctx.files.readBytes and serving them as blob URLs —
the same pattern used by the image-viewer extension.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@davideweaver davideweaver merged commit 9d06948 into main Jun 30, 2026
3 checks passed
@davideweaver davideweaver deleted the feat/markdown-preview-html-images branch June 30, 2026 15:41
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