Skip to content

Keep block image URLs on one line when wrapping - #18

Open
nickweisser wants to merge 1 commit into
dmsnell:trunkfrom
nickweisser:fix/block-image-wrap
Open

nickweisser wants to merge 1 commit into
dmsnell:trunkfrom
nickweisser:fix/block-image-wrap

Conversation

@nickweisser

Copy link
Copy Markdown

When line_wrap() wraps a paragraph, links are protected by the U+E0001 / U+E007F markers that Line_Buffer puts around them. Block images don't get these markers, so a long image URL is split across lines:

![](https://i0.wp.com/wordpress.org/news/files/2026/11/reprint-hero-scaled.png?resize
=2560%2C1440&ssl=1)

A CommonMark link destination can't contain a line ending, so this no longer parses as an image. You can see it on wordpress.org right now: all 51 images in https://wordpress.org/news/2026/11/wc-asia-2027-penang/?output_format=md are split like this. Same for https://wordpress.org/news/2026/11/reprint-your-site/?output_format=md.

This PR wraps the block image output in the same markers as links, so line_wrap() treats the whole image as unbreakable. Wrapping of normal text is unchanged.

Testing:

  • Added a spec document to tests/spec-documents/line-wrapping-1.html. It fails on trunk and passes with this change. All 64 tests pass.
  • Ran it against a real post with 16 images and 6 tables (default soft_line_wrap of 80). Before: 16 broken image URLs. After: 0. Only the image lines change in the output.

AI assistance: I used Claude Code (Claude Opus 5.5) to find the cause, write the change and the test, and compare the output. I reviewed the diff and the test results myself.

Links are protected from line_wrap() by the U+E0001/U+E007F markers,
block images were not, so long image URLs got split across lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BmWt9BEUBt7RHPQWWDwZYt
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