summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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()