summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/model/link.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2025-07-09 10:16:36 +0200
committerGitHub <noreply@github.com>2025-07-09 08:16:36 +0000
commite5e1dcd9c01341d2cd3473ac94a70223d5966086 (patch)
treed648efad9463cb10270d55ba35210eeb1e91ee22 /crates/typst-library/src/model/link.rs
parent0a3c6939dd274f40672484695d909c2cc0d0d755 (diff)
Target-specific native show rules (#6569)
Diffstat (limited to 'crates/typst-library/src/model/link.rs')
-rw-r--r--crates/typst-library/src/model/link.rs41
1 files changed, 3 insertions, 38 deletions
diff --git a/crates/typst-library/src/model/link.rs b/crates/typst-library/src/model/link.rs
index 1e2c708e..c630835e 100644
--- a/crates/typst-library/src/model/link.rs
+++ b/crates/typst-library/src/model/link.rs
@@ -2,13 +2,10 @@ use std::ops::Deref;
use ecow::{eco_format, EcoString};
-use crate::diag::{bail, warning, At, SourceResult, StrResult};
-use crate::engine::Engine;
+use crate::diag::{bail, StrResult};
use crate::foundations::{
- cast, elem, Content, Label, NativeElement, Packed, Repr, Show, ShowSet, Smart,
- StyleChain, Styles, TargetElem,
+ cast, elem, Content, Label, Packed, Repr, ShowSet, Smart, StyleChain, Styles,
};
-use crate::html::{attr, tag, HtmlElem};
use crate::introspection::Location;
use crate::layout::Position;
use crate::text::TextElem;
@@ -38,7 +35,7 @@ use crate::text::TextElem;
/// # Syntax
/// This function also has dedicated syntax: Text that starts with `http://` or
/// `https://` is automatically turned into a link.
-#[elem(Show)]
+#[elem]
pub struct LinkElem {
/// The destination the link points to.
///
@@ -103,38 +100,6 @@ impl LinkElem {
}
}
-impl Show for Packed<LinkElem> {
- #[typst_macros::time(name = "link", span = self.span())]
- fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
- let body = self.body.clone();
-
- Ok(if styles.get(TargetElem::target).is_html() {
- if let LinkTarget::Dest(Destination::Url(url)) = &self.dest {
- HtmlElem::new(tag::a)
- .with_attr(attr::href, url.clone().into_inner())
- .with_body(Some(body))
- .pack()
- .spanned(self.span())
- } else {
- engine.sink.warn(warning!(
- self.span(),
- "non-URL links are not yet supported by HTML export"
- ));
- body
- }
- } else {
- 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)
- }
- }
- })
- }
-}
-
impl ShowSet for Packed<LinkElem> {
fn show_set(&self, _: StyleChain) -> Styles {
let mut out = Styles::new();