mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
Move no-hyphenation style in link from show to show-set rule (#5731)
This commit is contained in:
parent
b90ad470d6
commit
b45f574703
@ -6,8 +6,8 @@ use smallvec::SmallVec;
|
||||
use crate::diag::{bail, warning, At, SourceResult, StrResult};
|
||||
use crate::engine::Engine;
|
||||
use crate::foundations::{
|
||||
cast, elem, Content, Label, NativeElement, Packed, Repr, Show, Smart, StyleChain,
|
||||
TargetElem,
|
||||
cast, elem, Content, Label, NativeElement, Packed, Repr, Show, ShowSet, Smart,
|
||||
StyleChain, Styles, TargetElem,
|
||||
};
|
||||
use crate::html::{attr, tag, HtmlElem};
|
||||
use crate::introspection::Location;
|
||||
@ -16,7 +16,7 @@ use crate::text::{Hyphenate, TextElem};
|
||||
|
||||
/// Links to a URL or a location in the document.
|
||||
///
|
||||
/// By default, links are not styled any different from normal text. However,
|
||||
/// By default, links do not look any different from normal text. However,
|
||||
/// you can easily apply a style of your choice with a show rule.
|
||||
///
|
||||
/// # Example
|
||||
@ -31,6 +31,11 @@ use crate::text::{Hyphenate, TextElem};
|
||||
/// ]
|
||||
/// ```
|
||||
///
|
||||
/// # Hyphenation
|
||||
/// If you enable hyphenation or justification, by default, it will not apply to
|
||||
/// links to prevent unwanted hyphenation in URLs. You can opt out of this
|
||||
/// default via `{show link: set text(hyphenate: true)}`.
|
||||
///
|
||||
/// # Syntax
|
||||
/// This function also has dedicated syntax: Text that starts with `http://` or
|
||||
/// `https://` is automatically turned into a link.
|
||||
@ -119,20 +124,26 @@ impl Show for Packed<LinkElem> {
|
||||
body
|
||||
}
|
||||
} else {
|
||||
let linked = match &self.dest {
|
||||
match &self.dest {
|
||||
LinkTarget::Dest(dest) => body.linked(dest.clone()),
|
||||
LinkTarget::Label(label) => {
|
||||
let elem = engine.introspector.query_label(*label).at(self.span())?;
|
||||
let dest = Destination::Location(elem.location().unwrap());
|
||||
body.clone().linked(dest)
|
||||
}
|
||||
};
|
||||
|
||||
linked.styled(TextElem::set_hyphenate(Hyphenate(Smart::Custom(false))))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ShowSet for Packed<LinkElem> {
|
||||
fn show_set(&self, _: StyleChain) -> Styles {
|
||||
let mut out = Styles::new();
|
||||
out.set(TextElem::set_hyphenate(Hyphenate(Smart::Custom(false))));
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
fn body_from_url(url: &Url) -> Content {
|
||||
let text = ["mailto:", "tel:"]
|
||||
.into_iter()
|
||||
|
Loading…
x
Reference in New Issue
Block a user