mirror of
https://github.com/typst/typst
synced 2025-05-15 09:35:28 +08:00
Fix panic in link linebreaking (#4579)
This commit is contained in:
parent
0ea4b1b217
commit
4275447788
@ -655,9 +655,9 @@ fn breakpoints(p: &Preparation, mut f: impl FnMut(usize, Breakpoint)) {
|
|||||||
let (head, tail) = text.split_at(last);
|
let (head, tail) = text.split_at(last);
|
||||||
if head.ends_with("://") || tail.starts_with("www.") {
|
if head.ends_with("://") || tail.starts_with("www.") {
|
||||||
let (link, _) = link_prefix(tail);
|
let (link, _) = link_prefix(tail);
|
||||||
let end = last + link.len();
|
|
||||||
linebreak_link(link, |i| f(last + i, Breakpoint::Normal));
|
linebreak_link(link, |i| f(last + i, Breakpoint::Normal));
|
||||||
while iter.peek().is_some_and(|&p| p < end) {
|
last += link.len();
|
||||||
|
while iter.peek().is_some_and(|&p| p < last) {
|
||||||
iter.next();
|
iter.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -687,19 +687,17 @@ fn breakpoints(p: &Preparation, mut f: impl FnMut(usize, Breakpoint)) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Hyphenate between the last and current breakpoint.
|
// Hyphenate between the last and current breakpoint.
|
||||||
if hyphenate {
|
if hyphenate && last < point {
|
||||||
let mut offset = last;
|
|
||||||
for segment in text[last..point].split_word_bounds() {
|
for segment in text[last..point].split_word_bounds() {
|
||||||
if !segment.is_empty() && segment.chars().all(char::is_alphabetic) {
|
if !segment.is_empty() && segment.chars().all(char::is_alphabetic) {
|
||||||
hyphenations(p, &lb, offset, segment, &mut f);
|
hyphenations(p, &lb, last, segment, &mut f);
|
||||||
}
|
}
|
||||||
offset += segment.len();
|
last += segment.len();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call `f` for the UAX #14 break opportunity.
|
// Call `f` for the UAX #14 break opportunity.
|
||||||
f(point, breakpoint);
|
f(point, breakpoint);
|
||||||
|
|
||||||
last = point;
|
last = point;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
tests/ref/issue-hyphenate-in-link.png
Normal file
BIN
tests/ref/issue-hyphenate-in-link.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
@ -107,3 +107,11 @@ For info see #link("https://myhost.tld").
|
|||||||
#set page(width: 50pt, height: auto)
|
#set page(width: 50pt, height: auto)
|
||||||
#h(99%) 🏳️🌈
|
#h(99%) 🏳️🌈
|
||||||
🏳️🌈
|
🏳️🌈
|
||||||
|
|
||||||
|
--- issue-hyphenate-in-link ---
|
||||||
|
#set par(justify: true)
|
||||||
|
|
||||||
|
// The `linebreak()` function accidentally generated out-of-order breakpoints
|
||||||
|
// for links because it now splits on word boundaries. We avoid the link markup
|
||||||
|
// syntax because it's show rule interferes.
|
||||||
|
#"http://creativecommons.org/licenses/by-nc-sa/4.0/"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user