Repository navigation
fix(layout): honour white-space:nowrap on inline elements - #295
Merged
Merged
Conversation
Only the block container's white-space decided whether a line could wrap, so <span style="white-space:nowrap">…</span> inside a normal heading still wrapped at every space. CSS Text 3 §3: white-space applies to all elements; §5.5: the white-space property on the nearest common ancestor of the two characters controls breaking at their boundary. After collection, each item whose common ancestor with the previous item is nowrap/pre gets NoWrapBefore: glueRun keeps such items in one run (counting the space between them), and forceOne places a whole nowrap run that is wider than the line as one overflowing piece instead of tearing it apart one word per line. Boundaries around the span still wrap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In a 400px
<h1>(20px),<span style="white-space:nowrap">A rather long heading that would wrap over two lines otherwise</span>still wrapped: h1 52px tall, span on two lines.white-space:nowrapon the h1 itself gave one line.Spec read
Root cause
Only the block container's white-space reached line breaking:
blockOrInlineContentscomputed a singlenowrapflag (layout/layout.go:518). Every inter-word space was a wrap opportunity (glueRunglued only items withSpaceBefore == 0), whatever the inline ancestors said.Change
InlineItem.NoWrapBefore, set after collection bymarkNoWrapwhen the nearest common ancestor of an item and the previous one haswhite-space: nowraporpre.glueRunkeeps such items in one run and counts the space between them.forceOneplaces a whole nowrap run that is wider than the line as one overflowing piece, instead of one word per line.Checked
preon an inline span already did not wrap: its preserved spaces are not break points. Covered by the test.pre-wrapandpre-lineare parsed aspre(css/parse.go:789), so a block with them never wraps. That is wrong: both should wrap.break-spacesis not parsed at all. Not fixed here; reported.Tests
TestInlineWhiteSpaceNowrap(RenderHTML + script measuring h1/span heights): nowrap span → one line, and a break before a nowrap span (52,26). Failed on main (52,52 / 52,52). Controls: nowrap on the block, pre span, normal span.TestInlineNowrapSpan(layout unit): an overflowing nowrap run stays whole. layout coverage 100.0%.🤖 Generated with Claude Code