Skip to content

feat(glowm): add image rendering support#15

Merged
denolfe merged 9 commits intomainfrom
feat/glowm-images
Feb 14, 2026
Merged

feat(glowm): add image rendering support#15
denolfe merged 9 commits intomainfrom
feat/glowm-images

Conversation

@denolfe
Copy link
Owner

@denolfe denolfe commented Feb 14, 2026

Overview

Adds inline image rendering to glowm, the terminal markdown renderer. Images display directly in the terminal using the Kitty graphics protocol (for Ghostty/Kitty) or ANSI block characters as fallback.

Key Changes

  • New lib/images.ts module handles all image processing

    • Kitty graphics protocol for native rendering in supported terminals
    • ANSI block fallback via terminal-image for other terminals
    • SVG files show alt text + URL (rasterization not supported)
  • Reference-style markdown support

    • ![alt][ref] images resolved to inline syntax before processing
    • [![alt][imgref]][linkref] linked images handled as single units
  • Image presentation

    • 2-space left padding to match other content
    • Centered, italicized captions below images
    • Badge-style linked images show the link URL in fallback text

Design Decisions

The Kitty protocol writes directly to stdout rather than returning a string. To avoid escape sequences being mangled by the markdown parser, images are replaced with null-byte placeholders before marked processes the document. After rendering, the output is streamed segment by segment, with actual image data written when placeholders are encountered.

For linked images like [![badge](img.svg)](link), the fallback displays the outer link URL rather than the image URL since badges are typically SVGs (which can't render) and the link destination is more useful information.

Overall Flow

sequenceDiagram
    participant M as Markdown Input
    participant R as resolveReferenceImages
    participant P as prepareImages
    participant X as marked()
    participant O as outputWithImages
    participant T as Terminal

    M->>R: Raw markdown
    R->>P: Resolved references
    P->>P: Replace images with placeholders
    P->>X: Markdown with placeholders
    X->>O: Rendered HTML-ish string
    O->>T: Stream text segments
    O->>T: Write Kitty/ANSI images at placeholders
Loading

Example

image

- Add lib/images.ts for image processing and rendering
- Support Kitty graphics protocol for native image display in Ghostty
- Fall back to ANSI block rendering for other terminals
- Use placeholder-based approach to avoid marked escaping Kitty sequences
- Remove styleImage from renderers (replaced by images.ts)
- Resolve reference-style images ![alt][ref] to inline syntax
- Handle linked images [![alt](img)](url) as single unit
- Resolve reference-style linked images [![alt][imgref]][linkref]
- Skip SVG files (can't be rendered by terminal-image)
- Remove "(failed to load)" from fallback output
- Show link URL instead of image URL for linked image fallbacks
- Update tests for new image handling
- Remove replaceImageBlocks (not compatible with Kitty protocol)
- Add 5s timeout for remote image fetches
- Strip reference definition lines after resolving
- Update tests to use prepareImages directly
@denolfe denolfe merged commit 62512dc into main Feb 14, 2026
2 checks passed
@denolfe denolfe deleted the feat/glowm-images branch February 14, 2026 20:40
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