Repository navigation
Description
Description
UAX #14: Unicode Line Breaking Algorithm does not handle URLs well, so Typst adds a special linebreak_link() function.
Recently, #8039 improved the condition for calling linebreak_link().
However, it (accidentally?) changed the line break opportunities among :// in https://example.com:
- In Typst v0.15.1,
https://always stays on the same line. - On
main,http://can be split into three lines:http:,/,/.
I suggest we revert to the old behavor.
More tests
Test code
#for link in (
"https://example.com/foo_bar",
"git+https://git.repo/some_pkg.git@feature",
"http://0.0.0.0:8000/foo_bar",
"http://1up.example/foo_bar",
) {
block(width: 0pt, link)
line(length: 100%, stroke: gray)
}- Left: 7ad9c34, the last commit before Fix line breaking for hosts starting with a digit #8039.
- Right: 32fd4cc, the commit that merged Fix line breaking for hosts starting with a digit #8039.
Expected result
https://
example.
com/
foo_
bar
git+
https://
git.
repo/
some_
pkg.
git@
feature
http://
0.
0.
0.
0:
8000/
foo_
bar
http://
1
up.
example/
foo_
bar
Cause
Before #8039, the input of linebreak_link did not include the scheme or ://. For example, linebreak_link("example.com/foo_bar", ..).
After #8039, the input became the full URL. For example, linebreak_link("https://example.com/foo_bar", ..).
linebreak_link was not designed to handle the scheme or ://, so it produced bad results.
Additional info
#9002 is related.
The initial motive of #8039 was to add a line break opportunity after ://, even when the domain starts with a number (e.g., IP host).
The current ICU4X line segmenter used by Typst is targeting Unicode 15.1. In this version of UAX #14, https:// followed by a letter (e.g., https://a) produces an opportunity, but https:// followed by a number (e.g., https://0) does not, because the latter matches SY × NU (do not break between / and numbers) in the rule LB25.
However, LB25 was modified in Unicode 16. The latest LB25 no longer contains SY × NU1, so ICU4X neo line segmenter (targeting Unicode 18) treats https://a and https://0 as equal.
Nevertheless, that does not mean that this issue can be fixed by reverting #8039 and switching to the neo line segmenter.
#8093 added a test case for a+cool.scheme://a.com/ and expected the line to be broke after cool., which I concur.
By Unicode 18, UAX #14 still can't handle this case well: it does not produce any line break opportunity among a+cool.scheme://.
As a result, passing full URLs to linebreak_link() is necessary.
Therefore, I suggest we add / as a dedicated Class::Slash, and forbid line breaks before all slashes.
typst/crates/typst-layout/src/inline/linebreak.rs
Lines 869 to 879 in 84cca40
| impl Class { | |
| fn of(c: char) -> Self { | |
| if c.is_alphabetic() { | |
| Class::Alphabetic | |
| } else if c.is_numeric() { | |
| Class::Digit | |
| } else if matches!(c, '(' | '[') { | |
| Class::Open | |
| } else { | |
| Class::Other | |
| } |
typst/crates/typst-layout/src/inline/linebreak.rs
Lines 886 to 897 in 84cca40
| for (end, c) in link.char_indices() { | |
| let class = Class::of(c); | |
| // Emit opportunities when going from | |
| // - other -> other | |
| // - alphabetic -> numeric | |
| // - numeric -> alphabetic | |
| // Never before/after opening delimiters. | |
| if end > 0 | |
| && prev != Class::Open | |
| && if class == Class::Other { prev == Class::Other } else { class != prev } | |
| { |
Operating system
Linux, Web app, Windows
Typst version
- I am using the latest version of Typst
Note that this issue does not exist in Typst v0.15.1. It exists on main.
Footnotes
-
LB25 still contains
NU ( SY | IS )* × NU. That is irrelevant to this issue, though. ↩
Activity