summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Schmitz <tobiasschmitz2001@gmail.com>2025-07-09 02:09:28 +0200
committerTobias Schmitz <tobiasschmitz2001@gmail.com>2025-07-09 10:18:48 +0200
commitdf10cb8570defebda79f000c9ea4bd16eff81102 (patch)
tree7b32e24a80424d87b98c5a77aa84820aef0e14e9
parent08719237c2877c5a3337b888bbc84c42fddcbdb0 (diff)
feat: default to the url if no alt text is specified for a link
-rw-r--r--crates/typst-library/src/model/link.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/crates/typst-library/src/model/link.rs b/crates/typst-library/src/model/link.rs
index 4d121e3c..6203436e 100644
--- a/crates/typst-library/src/model/link.rs
+++ b/crates/typst-library/src/model/link.rs
@@ -128,7 +128,10 @@ impl Show for Packed<LinkElem> {
} else {
let alt = self.alt.get_cloned(styles);
match &self.dest {
- LinkTarget::Dest(dest) => body.linked(dest.clone(), alt),
+ LinkTarget::Dest(dest) => {
+ let url = || dest.as_url().map(|url| url.clone().into_inner());
+ body.linked(dest.clone(), alt.or_else(url))
+ }
LinkTarget::Label(label) => {
let elem = engine.introspector.query_label(*label).at(self.span())?;
let dest = Destination::Location(elem.location().unwrap());
@@ -190,7 +193,15 @@ pub enum Destination {
Location(Location),
}
-impl Destination {}
+impl Destination {
+ pub fn as_url(&self) -> Option<&Url> {
+ if let Self::Url(v) = self {
+ Some(v)
+ } else {
+ None
+ }
+ }
+}
impl Repr for Destination {
fn repr(&self) -> EcoString {