Annotate href labels with PDF link targets

This commit is contained in:
gloamxun committed 2026-10-19 21:33:26 +08:00
1 parent 88646c9453
commit 05d7980561
7 files changed
+68 -35

No files matched your search

+3
View File
@@ -99,6 +99,8 @@ pub struct DocumentModel {
pub labels: HashMap<String, String>,
pub citations: HashMap<String, usize>,
pub citation_metadata: HashMap<String, CitationMetadata>,
/// Display text -> hyperlink URL for `\href` annotations.
pub link_targets: HashMap<String, String>,
/// Bibliography keys in the order their metadata was declared. Needed to
/// assign natbib-style year suffixes (2014a, 2014b, ...) deterministically.
pub bibliography_order: Vec<String>,
@@ -128,6 +130,7 @@ impl Default for DocumentModel {
labels: HashMap::new(),
citations: HashMap::new(),
citation_metadata: HashMap::new(),
link_targets: HashMap::new(),
bibliography_order: Vec::new(),
author_year_citations: false,
footnotes: Vec::new(),
@@ -1155,6 +1155,9 @@ impl Parser {
expanded::FrontendEventKind::LinkStart => {
self.link_depth = self.link_depth.saturating_add(1);
}
expanded::FrontendEventKind::LinkTarget { text, url } => {
self.document.link_targets.insert(text.clone(), url.clone());
}
expanded::FrontendEventKind::LinkEnd => {
self.link_depth = self.link_depth.saturating_sub(1);
}
+5
View File
@@ -266,6 +266,11 @@ pub enum FrontendEventKind {
PageNumber,
/// Start of hyperlink material.
LinkStart,
/// `\href` target: display text and URL, used for PDF annotations.
LinkTarget {
text: String,
url: String,
},
/// End of hyperlink material.
LinkEnd,
/// A package or class was loaded from a local file.