Repository navigation
fix: white-space pre-wrap, break-spaces and pre-line wrap - #296
Merged
Merged
Conversation
pre-wrap and pre-line were parsed as pre and break-spaces not at all, so a block using them never wrapped - Marp themes set white-space:pre-wrap on code blocks. Per the CSS Text 3 §3 table: - pre-wrap: spaces and newlines preserved, wraps; a run of spaces is a soft wrap opportunity at its end and hangs at the end of a line (§4.1.2) - leading indentation stays part of the first word, inner runs become the next word's SpaceBefore at their real width; - break-spaces: preserved and wraps, but spaces never hang: they stay in the previous word's width and the next word carries a new BreakBefore wrap opportunity; - pre-line: spaces collapse as in normal, newlines are forced breaks. The text's own element now decides (its inherited white-space), so a white-space:normal span inside a <pre> collapses as in a browser. Min-content treats only pre and nowrap as unbreakable. 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
white-space: pre-wrapandpre-linewere parsed aspre(css/parse.go:789), so a block using them never wrapped.break-spaceswas not parsed at all. Marp themes put code inprewithwhite-space: pre-wrap.Spec read
Change
css.WSPreWrap,WSBreakSpaces,WSPreLineandWhiteSpace.PreservesSpaces().appendWordsnow uses the text's own inherited white-space:SpaceBeforeat its real width, so it is a wrap opportunity and hangs at a line edge. A line of only spaces hangs entirely.InlineItem.BreakBeforeopportunity thatglueRunhonours. Breaking between two spaces of one run is not modelled.white-space: normalspan inside<pre>now collapses (its own value decides). The block's no-wrap placement forpreis unchanged.Tests
TestWhiteSpaceWrappingValues(RenderHTML + script measuring boxes): pre-wrap, break-spaces and pre-line blocks wrap; pre-wrap keeps spaces and indentation; pre-line collapses spaces; newlines are kept for all three. Failed on main (no wrapping, pre-line kept spaces, break-spaces lost the newline).prestays one line (control).🤖 Generated with Claude Code