From df10cb8570defebda79f000c9ea4bd16eff81102 Mon Sep 17 00:00:00 2001 From: Tobias Schmitz Date: Wed, 9 Jul 2025 02:09:28 +0200 Subject: [PATCH] feat: default to the url if no alt text is specified for a link --- crates/typst-library/src/model/link.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/typst-library/src/model/link.rs b/crates/typst-library/src/model/link.rs index 4d121e3c7..6203436e6 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 { } 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 {