Skip to content

fix: preserve percentage image widths after reload - #372

Merged
hunghg255 merged 1 commit into
hunghg255:mainfrom
Found-L:fix/image-percentage-width
Jul 28, 2026
Merged

fix: preserve percentage image widths after reload#372
hunghg255 merged 1 commit into
hunghg255:mainfrom
Found-L:fix/image-percentage-width

Conversation

@Found-L

@Found-L Found-L commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Preserve percentage-based image widths when parsing HTML.
  • Apply the same width parsing behavior to inline and block image nodes.
  • Keep the existing behavior for pixel and numeric widths unchanged.

Problem

Image widths such as 100% were parsed with Number.parseInt, which converted them to 100. After reloading the document, this numeric value was rendered as 100px, causing percentage-sized images to shrink unexpectedly.

Changes

Added a shared image width parser that:

  • preserves percentage widths as strings, such as 100%
  • parses pixel and numeric widths as numbers, such as 500px to 500
  • returns null when no width is provided

The parser is now used by all HTML parsing paths for both Image and ImageBlock.

Validation

  • Verified that 100% remains 100% for inline and block images after reloading.
  • Verified that 500px continues to parse as 500.
  • Passed pnpm type-check.
  • Passed pnpm build:lib.
  • Passed git diff --check.

Fixes #147

@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

@Found-L is attempting to deploy a commit to the Gia Hung's projects Team on Vercel.

A member of the Team first needs to authorize it.

@hunghg255
hunghg255 merged commit 961761c into hunghg255:main Jul 28, 2026
1 of 3 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.

[Bug] The image size "L" is not parsed well.

2 participants