Skip to content

fix: preserve image attributes when a title is present#290

Open
nimonian wants to merge 2 commits into
comarkdown:mainfrom
nimonian:fix/img-attributes-with-title
Open

fix: preserve image attributes when a title is present#290
nimonian wants to merge 2 commits into
comarkdown:mainfrom
nimonian:fix/img-attributes-with-title

Conversation

@nimonian

Copy link
Copy Markdown

Fixes #289.

The image stringify handler returns early on the title branch and never appends the attribute block, so ![alt](src "title"){width="200"} round-trips to ![alt](src "title"), dropping width, class, and every other attribute. The parser already keeps them (the tree carries width); only rendering was lossy.

The fix appends the collected attributes on both branches (one line in packages/comark/src/internal/stringify/handlers/img.ts).

Two commits, so the regression is visible on its own:

  1. a failing test covering title + attribute images (the two controls pass, the two title+attribute cases fail)
  2. the one-line fix, turning the test green

Run the test:

pnpm --filter comark vitest run test/img-attributes.test.ts

Verified against current main: the new test is 4/4 green with the fix, and resolve-attributes / props / brackets stay green. Note: test/index.test.ts flakes independently of this change (some specs assert a 10ms parse budget that loses under CPU load), so it can fail intermittently on a clean main too.

🤖 Generated with Claude Code

nimonian and others added 2 commits July 25, 2026 17:15
The stringify handler for images returns early on the title branch and
never appends the attribute block, so `![alt](src "title"){width="200"}`
round-trips to `![alt](src "title")`, silently dropping width, class, and
every other attribute. The parser is fine (the tree keeps `width`); only
rendering is affected. Attributes-only and title-only images round-trip
correctly, so the two regression cases fail while the two controls pass.

Repro: pnpm --filter comark vitest run test/img-attributes.test.ts

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The image stringify handler returned early on the title branch and never
appended the attribute block, so `![alt](src "title"){width="200"}`
round-tripped to `![alt](src "title")`, dropping width, class, and every
other attribute. The parser already keeps them (the tree carries `width`);
only rendering was lossy. Append the attribute block on both branches.

Fixes the failing cases added in the previous commit.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nimonian
nimonian requested a review from farnabaz as a code owner July 25, 2026 16:20
@vercel

vercel Bot commented Jul 25, 2026

Copy link
Copy Markdown

@nimonian is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

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.

Image attributes are dropped when title is provided

1 participant