Repository navigation
Improve the line breaking algorithm for links - #9085
Open
YDX-2147483647 wants to merge 1 commit into
Open
YDX-2147483647 wants to merge 1 commit into
YDX-2147483647 wants to merge 1 commit into
Conversation
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.
UAX
#14: Unicode Line Breaking Algorithm does not handle URLs well, so Typst has a speciallinebreak_link()function.This PR improves two details of this function:
In Typst v0.15.1,
https://always stays on the same line; but Fix line breaking for hosts starting with a digit #8039 accidentally made it split into three parts:https:,/,/.This PR restores the old behavior by distinguishing slashes (
/,Class::Slash) from other characters (Class::Other), and forbiding line breaks before all slashes.Detailed analysis can be found in
https://should not be broke into three lines #9056.linebreak_link()has always had a special code that makes long pieces in URLs breakable. However onmain, that code is not effective for the last piece. For example:This PR fixes that by adding an additional call after the for-loop.
Additional considerations
Organization of the test code
The test util
assert_linebreaks()is put insidetest_linebreak_link(), because there might be anotherassert_linebreaks()added in the future. In #9002, oneassert_linebreaks()is forlinebreak_link(), and the other one is for the UAX#14algorithm.Non-ASCII URLs
No non-ASCII test cases are added, because the support of Typst for non-ASCII URLs is still somewhat limited, and I don't indent to change that in this PR.
Let's take https://en.wikipedia.org/wiki/Antonín_Dvořák as an example. (This example is copied from UTS
#58: Unicode Link Detection and Formatting: URLs and Email Addresses.)Typst v0.15.1,
main, and this PR all turn the above document1 to this:Well, that looks acceptable, but what
linebreak_link()actually receives ishttps://en.wikipedia.org/wiki/Anton— the rest part,ín_Dvořák, is left to the UAX#14algorithm…Footnotes
That URL does not need to be quoted. However, we are talking about line breaking rather than linkification, so I quote it to disable the smart linkification. ↩