mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +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::diag::{bail, warning, At, SourceResult, StrResult};
|
||||||
use crate::engine::Engine;
|
use crate::engine::Engine;
|
||||||
use crate::foundations::{
|
use crate::foundations::{
|
||||||
cast, elem, Content, Label, NativeElement, Packed, Repr, Show, Smart, StyleChain,
|
cast, elem, Content, Label, NativeElement, Packed, Repr, Show, ShowSet, Smart,
|
||||||
TargetElem,
|
StyleChain, Styles, TargetElem,
|
||||||
};
|
};
|
||||||
use crate::html::{attr, tag, HtmlElem};
|
use crate::html::{attr, tag, HtmlElem};
|
||||||
use crate::introspection::Location;
|
use crate::introspection::Location;
|
||||||
@ -16,7 +16,7 @@ use crate::text::{Hyphenate, TextElem};
|
|||||||
|
|
||||||
/// Links to a URL or a location in the document.
|
/// 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.
|
/// you can easily apply a style of your choice with a show rule.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # 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
|
/// # Syntax
|
||||||
/// This function also has dedicated syntax: Text that starts with `http://` or
|
/// This function also has dedicated syntax: Text that starts with `http://` or
|
||||||
/// `https://` is automatically turned into a link.
|
/// `https://` is automatically turned into a link.
|
||||||
@ -119,20 +124,26 @@ impl Show for Packed<LinkElem> {
|
|||||||
body
|
body
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let linked = match &self.dest {
|
match &self.dest {
|
||||||
LinkTarget::Dest(dest) => body.linked(dest.clone()),
|
LinkTarget::Dest(dest) => body.linked(dest.clone()),
|
||||||
LinkTarget::Label(label) => {
|
LinkTarget::Label(label) => {
|
||||||
let elem = engine.introspector.query_label(*label).at(self.span())?;
|
let elem = engine.introspector.query_label(*label).at(self.span())?;
|
||||||
let dest = Destination::Location(elem.location().unwrap());
|
let dest = Destination::Location(elem.location().unwrap());
|
||||||
body.clone().linked(dest)
|
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 {
|
fn body_from_url(url: &Url) -> Content {
|
||||||
let text = ["mailto:", "tel:"]
|
let text = ["mailto:", "tel:"]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user