From 12c66e36b53a640204dce25cb428c3784d2e3a78 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 15 Jul 2025 10:44:21 +0200 Subject: [PATCH] Link reference in HTML export --- crates/typst-library/src/model/reference.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/typst-library/src/model/reference.rs b/crates/typst-library/src/model/reference.rs index 4877409fa..f7922ef3e 100644 --- a/crates/typst-library/src/model/reference.rs +++ b/crates/typst-library/src/model/reference.rs @@ -5,12 +5,13 @@ use crate::diag::{bail, At, Hint, SourceResult}; use crate::engine::Engine; use crate::foundations::{ cast, elem, Cast, Content, Context, Func, IntoValue, Label, NativeElement, Packed, - Repr, Smart, StyleChain, Synthesize, + Repr, Smart, StyleChain, Synthesize, TargetElem, }; use crate::introspection::{Counter, CounterKey, Locatable}; use crate::math::EquationElem; use crate::model::{ - BibliographyElem, CiteElem, Destination, Figurable, FootnoteElem, Numbering, + BibliographyElem, CiteElem, Destination, Figurable, FootnoteElem, LinkElem, + LinkTarget, Numbering, }; use crate::text::TextElem; @@ -346,7 +347,14 @@ fn realize_reference( content = supplement + TextElem::packed("\u{a0}") + content; } - Ok(content.linked(Destination::Location(loc))) + Ok(if styles.get(TargetElem::target).is_html() { + LinkElem::new(LinkTarget::Dest(Destination::Location(loc)), content).pack() + } else { + // TODO: We should probably also use `LinkElem` in the paged target, but + // it's a bit breaking and it becomes hard to style links without + // affecting references, so this change should be well-considered. + content.linked(Destination::Location(loc)) + }) } /// Turn a reference into a citation.