aya-dev
aya-dev copied to clipboard
Doc page width problem
Try the following case:
var d = Doc.english("You are right, but \"Genshin Impact\" is a brand new open world adventure game by MHY.");
System.out.println(d.renderToString(16, false));
Doc will be rendered as
You are right, but
"Genshin Impact"
is a brand new open
world adventure game
by MHY
There are lines exceeding the width of 16.
I super, original
The doc printer checks whether to insert a line break or a space only in FlatAlt and Union, while Doc.english is a sequence of plain(), line(), plain(), line(), ... (line() is short for FlatAlt(a whitespace, a line break)).
The sentence above is cut into
plain(You), line(), plain(are), line(), plain(right,), line(), plain(but), line()
When the doc printed "You are right," to output, there were 2 printable widths remaining.
And now we are printing the line() after plain(right,). (As described, line() = FlatAlt(a whitespace, a line break)).
- Doc printer checks if
line remaining >= width of a whitespace, which evaluates to true. - So whitespace is printed, and now the line remains only 1 character.
- Then we are printing
plain(but), but this time we don't check the width.
Not really fixed
What about a plain(but) with page width 1 ?
What about a
plain(but)with page width1?
It will be rendered as: (no line break is inserted)
but
You can preview the result with WidthPreviewToy 😉