mirror of
https://github.com/typst/typst
synced 2025-07-27 14:27:56 +08:00
feat: default to the url if no alt text is specified for a link
This commit is contained in:
parent
08719237c2
commit
df10cb8570
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user