Skip to content

feat: render markdown images with click-to-enlarge lightbox#271

Merged
backnotprop merged 2 commits intobacknotprop:mainfrom
dgrissen2:feat/render-markdown-images
Mar 12, 2026
Merged

feat: render markdown images with click-to-enlarge lightbox#271
backnotprop merged 2 commits intobacknotprop:mainfrom
dgrissen2:feat/render-markdown-images

Conversation

@dgrissen2
Copy link
Contributor

Summary

Adds full ![alt](path) image rendering to the Viewer component. Previously, markdown image syntax was silently treated as plain text. Images now render inline with a click-to-enlarge lightbox overlay.

What's included

Image rendering

  • ![alt](path) markdown syntax now renders as actual <img> elements
  • Works in headings, paragraphs, list items, blockquotes, and table cells
  • Remote URLs (https://...) render directly; local paths proxy through /api/image
  • cursor-zoom-in on thumbnails hints they're interactive

Root cause of the silent failure

The InlineMarkdown special-character scanner (/[\*[]/)) did not include !, so althad its!consumed as plain text, leavingaltto match as a regular link. Fixed by adding!` to the scan set and placing the image regex before the link regex.

Click-to-enlarge lightbox

  • Click any image → full-screen dark overlay with image scaled to 90vw / 85vh
  • Alt text shown as caption below
  • Dismiss: Escape, backdrop click, or the cursor changes to zoom-out to make it obvious
  • Portaled to document.body — same pattern as ImageAnnotator

Relative path resolution

Markdown files commonly reference images with relative paths (./images/chart.png). The server's process.cwd() is not necessarily the markdown file's directory, so these paths were 404ing.

Fix: getImageSrc() now accepts an optional base directory and appends ?base=<dir> to the API URL. handleImage in shared-handlers.ts falls back to resolving the path relative to base when the primary path doesn't exist. App.tsx captures filePath from the /api/plan response (already sent by the annotate server) and derives imageBaseDir to pass to <Viewer>.

Files changed

File Change
packages/ui/components/Viewer.tsx Image regex, imageBaseDir/onImageClick prop chain, ImageLightbox component
packages/ui/components/ImageThumbnail.tsx getImageSrc(path, base?) optional base param
packages/editor/App.tsx Capture filePath → derive imageBaseDir → pass to Viewer
packages/server/shared-handlers.ts handleImage fallback resolution via ?base= query param

Test plan

  • Open a markdown file with ![alt](https://...) — remote image renders
  • Open a markdown file with ![alt](./relative/path.png) — local image renders
  • Open a markdown file with ![alt](/absolute/path.png) — absolute path renders
  • Click an image → lightbox opens with alt caption
  • Press Escape → lightbox closes
  • Click backdrop → lightbox closes
  • Regular [link](url) still works (not accidentally matched as image)
  • Inline image mid-paragraph renders without breaking surrounding text

🤖 Generated with Claude Code

Adds full inline image rendering to the Viewer for both annotate and
plan review modes. Previously, ![alt](path) syntax was treated as plain
text.

## What changed

### Viewer.tsx
- Added `![alt](path)` regex to InlineMarkdown before the link pattern.
  Images starting with `!` were silently falling through to plain text
  because `!` was not in the special-character scan set — added it.
- Added `imageBaseDir` prop (flows Viewer → BlockRenderer → InlineMarkdown)
  so relative image paths in markdown resolve against the annotated file's
  directory rather than the server's cwd.
- Added `onImageClick` callback (same prop chain) to open lightbox on click.
- Added `ImageLightbox` component: full-screen dark backdrop, image scaled
  to 90vw/85vh with object-contain, alt text caption, closes on Escape or
  backdrop click. Portaled to document.body.
- Images render with `cursor-zoom-in` to hint they're clickable.

### App.tsx
- Captures `filePath` from `/api/plan` response (already sent by annotate
  server) and derives `imageBaseDir` (directory of the markdown file).
- Passes `imageBaseDir` to `<Viewer>`.

### ImageThumbnail.tsx
- `getImageSrc()` now accepts an optional `base` parameter. For relative
  local paths, appends `&base=<dir>` to the `/api/image` query string.

### shared-handlers.ts
- `handleImage` falls back to resolving the path relative to a `base`
  query param when the primary path doesn't exist and the path is relative.
  Covers the common case of `![chart](./images/chart.png)` in a markdown
  file opened from an arbitrary directory.

## Behavior
- Remote URLs (https://...) render directly, no proxy.
- Absolute local paths route through /api/image as before.
- Relative paths resolve against the markdown file's directory via ?base=.
- Click any image → lightbox. Escape or click outside → dismiss.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@backnotprop
Copy link
Owner

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@backnotprop backnotprop merged commit 2d1016a into backnotprop:main Mar 12, 2026
8 of 10 checks passed
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