diff --git a/crates/typst-pdf/src/tags.rs b/crates/typst-pdf/src/tags.rs index 8e41ea2ff..5b5963946 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), Outline(OutlineCtx), OutlineEntry(Packed), Table(TableCtx), TableCell(Packed), + Link(LinkId, Packed), } impl StackEntryKind { @@ -409,16 +409,16 @@ pub(crate) fn handle_start(gc: &mut GlobalContext, elem: &Content) { } } else if let Some(_) = elem.to_packed::() { TagKind::Caption.into() - } else if let Some(link) = elem.to_packed::() { - 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::() { push_stack(gc, loc, StackEntryKind::Table(TableCtx::new(table.clone()))); return; } else if let Some(cell) = elem.to_packed::() { push_stack(gc, loc, StackEntryKind::TableCell(cell.clone())); return; + } else if let Some(link) = elem.to_packed::() { + 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);