Skip to content

fix: fold stacked image size comments - #455

Merged
ocavue merged 6 commits into
masterfrom
fix/magic-comment-chain
Aug 10, 2026
Merged

fix: fold stacked image size comments#455
ocavue merged 6 commits into
masterfrom
fix/magic-comment-chain

Conversation

@ocavue

@ocavue ocavue commented Aug 10, 2026

Copy link
Copy Markdown
Member

An image now folds the whole run of magic comments chained behind it (first one wins) and stripMagicComment drops the whole run, so documents where an unfolded rewrite once stacked a second comment render clean and collapse back to a single comment on the next resize. walk and walkResolvedLink now share one walkAtomChild dispatch so atom handling cannot drift between the top level and a link label again; adds parser, resize round-trip, and MarkdownView coverage for linked images.

Summary by CodeRabbit

  • Bug Fixes
    • Improved image resizing when images are placed inside links.
    • Preserved link destinations while updating image dimensions.
    • Consolidated consecutive image size comments into a single effective setting.
    • Ensured image metadata comments are handled consistently in linked and embedded content.
    • Corrected comment placement so content following linked images remains associated with the surrounding link.
  • Tests
    • Added coverage for linked image resizing, metadata handling, and rendered image previews.

RobinQu and others added 6 commits August 10, 2026 12:12
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

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
meowdown Ready Ready Preview Aug 10, 2026 5:09am

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e98c010c-d7de-47f4-8aa0-2a58bb07362d

📥 Commits

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

📒 Files selected for processing (7)
  • packages/core/src/extensions/image.test.ts
  • packages/core/src/extensions/inline-text-to-mark-chunks.test.ts
  • packages/core/src/extensions/inline-text-to-mark-chunks.ts
  • packages/core/src/extensions/magic-comment.test.ts
  • packages/core/src/extensions/magic-comment.ts
  • packages/markdown/src/inline.test.ts
  • packages/react/src/components/markdown-view.test.tsx

📝 Walkthrough

Walkthrough

Linked-image handling now uses shared atom traversal and supports consecutive magic-comment folding. Tests cover resizing, parsing, link-label behavior, comment placement, and rendered image width.

Changes

Linked image metadata handling

Layer / File(s) Summary
Atom traversal and comment folding
packages/core/src/extensions/inline-text-to-mark-chunks.ts, packages/core/src/extensions/magic-comment.ts
Atom processing is centralized for wikilinks, wiki embeds, and images. Resolved link labels skip consumed children. Consecutive image metadata comments are folded while preserving the first parsed metadata.
Core linked-image regression coverage
packages/core/src/extensions/image.test.ts, packages/core/src/extensions/inline-text-to-mark-chunks.test.ts, packages/core/src/extensions/magic-comment.test.ts
Tests cover linked-image resizing, stacked comments, comment precedence, folding boundaries, and removal of trailing comment runs.
Parser and renderer validation
packages/markdown/src/inline.test.ts, packages/react/src/components/markdown-view.test.tsx
Markdown tests verify comment placement within links. React tests verify linked-image width rendering.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • prosekit/meowdown#413: Both changes modify atom traversal and caret handling for wikilinks, embeds, and linked images.
  • prosekit/meowdown#445: Both changes modify link-label traversal in inline-text-to-mark-chunks.ts.
  • prosekit/meowdown#454: This PR extends linked-image handling with contiguous magic-comment folding and broader atom traversal.

Suggested reviewers: maccman

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/magic-comment-chain

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@455
npm i https://pkg.pr.new/@meowdown/markdown@455
npm i https://pkg.pr.new/@meowdown/react@455

commit: 23c5ee8

@github-actions

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 93.23% 4703 / 5044
🔵 Statements 90.93% 5287 / 5814
🔵 Functions 90.65% 1135 / 1252
🔵 Branches 86.44% 3373 / 3902
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/core/src/extensions/inline-text-to-mark-chunks.ts 95.29% 92.22% 100% 96.52% 337, 349, 368-369, 486, 495, 547, 648, 703, 749-750, 853
packages/core/src/extensions/magic-comment.ts 94.73% 92.3% 100% 100% 38
Generated in workflow #1790 for commit 23c5ee8 by the Vitest Coverage Report Action

@ocavue ocavue changed the title fix: fold stacked image size comments and share the atom child walk fix: fold stacked image size comments Aug 10, 2026
@ocavue
ocavue marked this pull request as ready for review August 10, 2026 11:08
@ocavue
ocavue merged commit dc5710c into master Aug 10, 2026
11 of 12 checks passed
@ocavue
ocavue deleted the fix/magic-comment-chain branch August 10, 2026 11:08
@ocavuebot ocavuebot mentioned this pull request 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