summaryrefslogtreecommitdiff
path: root/crates/typst-library/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2025-01-22 13:58:57 +0100
committerGitHub <noreply@github.com>2025-01-22 12:58:57 +0000
commitb45f574703f674c962e8678b4af0aabe081216a1 (patch)
tree08b188af054c2244e6a61e4c446b4a2398ef2c55 /crates/typst-library/src
parentb90ad470d60f4a90e3ba2e78aa4746fbe08783ab (diff)
Move no-hyphenation style in link from show to show-set rule (#5731)
Diffstat (limited to 'crates/typst-library/src')
-rw-r--r--crates/typst-library/src/model/link.rs25
1 files changed, 18 insertions, 7 deletions
diff --git a/crates/typst-library/src/model/link.rs b/crates/typst-library/src/model/link.rs
index 4558cb39..5df6bead 100644
--- a/crates/typst-library/src/model/link.rs
+++ b/crates/typst-library/src/model/link.rs
@@ -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()