summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Schmitz <tobiasschmitz2001@gmail.com>2025-06-26 20:44:04 +0200
committerTobias Schmitz <tobiasschmitz2001@gmail.com>2025-07-03 18:43:04 +0200
commit605681d4356a66f0d05b0d0036419db374852f8c (patch)
tree84a2e6bf6c291ef9f1fb33154151be362b800a6b
parent6ebe85d67877254683e8038ad7fbf262fd495636 (diff)
refactor: move link tagging code
-rw-r--r--crates/typst-pdf/src/tags.rs30
1 files changed, 15 insertions, 15 deletions
diff --git a/crates/typst-pdf/src/tags.rs b/crates/typst-pdf/src/tags.rs
index 8e41ea2f..5b596394 100644
--- a/crates/typst-pdf/src/tags.rs
+++ b/crates/typst-pdf/src/tags.rs
@@ -40,11 +40,11 @@ pub(crate) struct StackEntry {
pub(crate) enum StackEntryKind {
Standard(Tag),
- Link(LinkId, Packed<LinkMarker>),
Outline(OutlineCtx),
OutlineEntry(Packed<OutlineEntry>),
Table(TableCtx),
TableCell(Packed<TableCell>),
+ Link(LinkId, Packed<LinkMarker>),
}
impl StackEntryKind {
@@ -409,16 +409,16 @@ pub(crate) fn handle_start(gc: &mut GlobalContext, elem: &Content) {
}
} else if let Some(_) = elem.to_packed::<FigureCaption>() {
TagKind::Caption.into()
- } else if let Some(link) = elem.to_packed::<LinkMarker>() {
- let link_id = gc.tags.next_link_id();
- push_stack(gc, loc, StackEntryKind::Link(link_id, link.clone()));
- return;
} else if let Some(table) = elem.to_packed::<TableElem>() {
push_stack(gc, loc, StackEntryKind::Table(TableCtx::new(table.clone())));
return;
} else if let Some(cell) = elem.to_packed::<TableCell>() {
push_stack(gc, loc, StackEntryKind::TableCell(cell.clone()));
return;
+ } else if let Some(link) = elem.to_packed::<LinkMarker>() {
+ let link_id = gc.tags.next_link_id();
+ push_stack(gc, loc, StackEntryKind::Link(link_id, link.clone()));
+ return;
} else {
return;
};
@@ -448,16 +448,6 @@ pub(crate) fn handle_end(gc: &mut GlobalContext, loc: Location) {
let node = match entry.kind {
StackEntryKind::Standard(tag) => TagNode::Group(tag, entry.nodes),
- StackEntryKind::Link(_, link) => {
- let alt = link.alt.as_ref().map(EcoString::to_string);
- let tag = TagKind::Link.with_alt_text(alt);
- let mut node = TagNode::Group(tag, entry.nodes);
- // Wrap link in reference tag, if it's not a url.
- if let Destination::Position(_) | Destination::Location(_) = link.dest {
- node = TagNode::Group(TagKind::Reference.into(), vec![node]);
- }
- node
- }
StackEntryKind::Outline(ctx) => {
let nodes = ctx.build_outline(entry.nodes);
TagNode::Group(TagKind::TOC.into(), nodes)
@@ -487,6 +477,16 @@ pub(crate) fn handle_end(gc: &mut GlobalContext, loc: Location) {
return;
}
+ StackEntryKind::Link(_, link) => {
+ let alt = link.alt.as_ref().map(EcoString::to_string);
+ let tag = TagKind::Link.with_alt_text(alt);
+ let mut node = TagNode::Group(tag, entry.nodes);
+ // Wrap link in reference tag, if it's not a url.
+ if let Destination::Position(_) | Destination::Location(_) = link.dest {
+ node = TagNode::Group(TagKind::Reference.into(), vec![node]);
+ }
+ node
+ }
};
gc.tags.push(node);