Skip to content

fix: fold a linked image's trailing magic comment into the image mark - #454

Closed
RobinQu wants to merge 1 commit into
prosekit:masterfrom
RobinQu:fix/link-label-image-magic-comment
Closed

fix: fold a linked image's trailing magic comment into the image mark#454
RobinQu wants to merge 1 commit into
prosekit:masterfrom
RobinQu:fix/link-label-image-magic-comment

Conversation

@RobinQu

@RobinQu RobinQu commented Aug 10, 2026

Copy link
Copy Markdown

Problem

An image immediately followed by a sizing magic comment (![alt](img)<!-- {"width":N,"height":M} -->) folds the comment into the image mark: it round-trips as source and supplies the image's display width. That folding happens for a standalone image, but not for an image inside a link label:

[![alt](img.png)<!-- {"width":320} -->](/target)

Here walkResolvedLink's image call site never invoked takeMagicComment, so the comment was emitted as plain visible text — raw <!-- ... --> markup leaking into the rendered document (e.g. after persisting a resized linked image, the comment appears as text right after it).

Fix

Thread takeMagicComment through walkResolvedLink's Image branch — the same folding the standalone-image path already performs — and skip children a previous child has consumed. The per-child dispatch moves into walkResolvedLinkChild to stay within the statement limit.

Test

New case in inline-text-to-mark-chunks.test.ts: [![a](u)<!-- {"width":320} -->](/target) folds the comment into a single chunk carrying mdImage(src=u,alt=a,width=320) inside the link label, with no leaked comment text. It fails without the fix. Full @meowdown/core suite (1622 tests), typecheck, and lint all pass.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed image metadata handling when images appear inside inline links.
    • Preserved surrounding link formatting and destination URLs while applying image width metadata correctly.
    • Improved handling of nested links, images, wiki content, references, and autolinked URLs.

An image followed by a sizing magic comment folds that comment into the
image mark so it round-trips as source while supplying the width — but
only for a standalone image. Inside a link label
(`[![alt](img)<!-- {"width":N} -->](target)`) the comment was emitted
as plain visible text instead, leaking raw markup into the rendering.

Thread takeMagicComment through walkResolvedLink's image call site, the
same folding the standalone-image path already does, and extract the
per-child dispatch into walkResolvedLinkChild to stay within the
statement limit.
@vercel

vercel Bot commented Aug 10, 2026

Copy link
Copy Markdown

@RobinQu is attempting to deploy a commit to the ocavue's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b6864a62-9669-4336-a0ca-935e0c91e461

📥 Commits

Reviewing files that changed from the base of the PR and between cac527e and 7298436.

📒 Files selected for processing (2)
  • packages/core/src/extensions/inline-text-to-mark-chunks.test.ts
  • packages/core/src/extensions/inline-text-to-mark-chunks.ts

📝 Walkthrough

Walkthrough

The link-child walker now folds trailing image width comments into image marks within inline link labels. The change preserves surrounding link marks and destinations. A regression test covers the nested image case.

Changes

Inline link image metadata

Layer / File(s) Summary
Resolved-link child processing
packages/core/src/extensions/inline-text-to-mark-chunks.ts, packages/core/src/extensions/inline-text-to-mark-chunks.test.ts
walkResolvedLink delegates child handling, skips consumed ranges, and folds image-adjacent width comments. The regression test verifies mdImage(width=320) and the surrounding link URI.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • prosekit/meowdown#440: Both changes update link-child walking and metadata handling in inline-text-to-mark-chunks.ts.
  • prosekit/meowdown#445: Both changes update link-label parsing and preserve the outer link destination.

Suggested reviewers: ocavue, maccman

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main fix: folding a linked image's trailing magic comment into the image mark.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@meowdown/core@454
npm i https://pkg.pr.new/@meowdown/markdown@454
npm i https://pkg.pr.new/@meowdown/react@454

commit: 7298436

@ocavue

ocavue commented Aug 10, 2026

Copy link
Copy Markdown
Member

Thanks for pointing this out! I've tweaked it a bit and merged it as #455.

@ocavue ocavue closed this Aug 10, 2026
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