From d9356abb39295c6d8b285ca827944627c1b7aff2 Mon Sep 17 00:00:00 2001 From: Tobias Schmitz Date: Wed, 30 Jul 2025 18:40:45 +0200 Subject: [PATCH] refactor: use TagNode::group function --- crates/typst-pdf/src/tags/list.rs | 12 ++++++------ crates/typst-pdf/src/tags/mod.rs | 14 +++++++------- crates/typst-pdf/src/tags/outline.rs | 6 +++--- crates/typst-pdf/src/tags/table.rs | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/crates/typst-pdf/src/tags/list.rs b/crates/typst-pdf/src/tags/list.rs index 66d31448d..38bbe8378 100644 --- a/crates/typst-pdf/src/tags/list.rs +++ b/crates/typst-pdf/src/tags/list.rs @@ -68,7 +68,7 @@ impl ListCtx { } pub(crate) fn push_bib_entry(&mut self, nodes: Vec) { - let nodes = vec![TagNode::Group(Tag::BibEntry.into(), nodes)]; + let nodes = vec![TagNode::group(Tag::BibEntry, nodes)]; // Bibliography lists cannot be nested, but may be missing labels. if let Some(item) = self.items.last_mut().filter(|item| item.body.is_none()) { item.body = Some(nodes); @@ -83,17 +83,17 @@ impl ListCtx { pub(crate) fn build_list(self, mut nodes: Vec) -> TagNode { for item in self.items.into_iter() { - nodes.push(TagNode::Group( - Tag::LI.into(), + nodes.push(TagNode::group( + Tag::LI, vec![ - TagNode::Group(Tag::Lbl.into(), item.label), - TagNode::Group(Tag::LBody.into(), item.body.unwrap_or_default()), + TagNode::group(Tag::Lbl, item.label), + TagNode::group(Tag::LBody, item.body.unwrap_or_default()), ], )); if let Some(sub_list) = item.sub_list { nodes.push(sub_list); } } - TagNode::Group(Tag::L(self.numbering).into(), nodes) + TagNode::group(Tag::L(self.numbering), nodes) } } diff --git a/crates/typst-pdf/src/tags/mod.rs b/crates/typst-pdf/src/tags/mod.rs index 3827bf5db..f3defe107 100644 --- a/crates/typst-pdf/src/tags/mod.rs +++ b/crates/typst-pdf/src/tags/mod.rs @@ -340,7 +340,7 @@ fn pop_stack(gc: &mut GlobalContext, entry: StackEntry) { // PDF/UA compliance of the structure hierarchy is checked // elsewhere. While this doesn't make a lot of sense, just // avoid crashing here. - gc.tags.push(TagNode::Group(Tag::TOCI.into(), entry.nodes)); + gc.tags.push(TagNode::group(Tag::TOCI, entry.nodes)); return; }; @@ -354,7 +354,7 @@ fn pop_stack(gc: &mut GlobalContext, entry: StackEntry) { // elsewhere. While this doesn't make a lot of sense, just // avoid crashing here. let tag = Tag::TD.with_location(Some(cell.span().into_raw())); - gc.tags.push(TagNode::Group(tag.into(), entry.nodes)); + gc.tags.push(TagNode::group(tag, entry.nodes)); return; }; @@ -379,19 +379,19 @@ fn pop_stack(gc: &mut GlobalContext, entry: StackEntry) { } StackEntryKind::Figure(ctx) => { let tag = Tag::Figure(ctx.alt).with_bbox(ctx.bbox.get()); - TagNode::Group(tag.into(), entry.nodes) + TagNode::group(tag, entry.nodes) } StackEntryKind::Formula(ctx) => { let tag = Tag::Formula(ctx.alt).with_bbox(ctx.bbox.get()); - TagNode::Group(tag.into(), entry.nodes) + TagNode::group(tag, entry.nodes) } StackEntryKind::Link(_, link) => { let alt = link.alt.as_ref().map(EcoString::to_string); let tag = Tag::Link.with_alt_text(alt); - let mut node = TagNode::Group(tag.into(), entry.nodes); + 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(Tag::Reference.into(), vec![node]); + node = TagNode::group(Tag::Reference, vec![node]); } node } @@ -411,7 +411,7 @@ fn pop_stack(gc: &mut GlobalContext, entry: StackEntry) { StackEntryKind::FootnoteEntry(footnote_loc) => { // Store footnotes separately so they can be inserted directly after // the footnote reference in the reading order. - let tag = TagNode::Group(Tag::Note.into(), entry.nodes); + let tag = TagNode::group(Tag::Note, entry.nodes); let ctx = gc.tags.footnotes.entry(footnote_loc).or_insert(FootnoteCtx::new()); ctx.entry = Some(tag); return; diff --git a/crates/typst-pdf/src/tags/outline.rs b/crates/typst-pdf/src/tags/outline.rs index 84c741493..4ce5e57da 100644 --- a/crates/typst-pdf/src/tags/outline.rs +++ b/crates/typst-pdf/src/tags/outline.rs @@ -29,7 +29,7 @@ impl OutlineCtx { } } - let section_entry = TagNode::Group(Tag::TOCI.into(), nodes); + let section_entry = TagNode::group(Tag::TOCI, nodes); self.push(outline_nodes, section_entry); } @@ -49,7 +49,7 @@ impl OutlineCtx { while !self.stack.is_empty() { self.finish_section(&mut outline_nodes); } - TagNode::Group(Tag::TOC.into(), outline_nodes) + TagNode::group(Tag::TOC, outline_nodes) } } @@ -68,6 +68,6 @@ impl OutlineSection { } fn into_tag(self) -> TagNode { - TagNode::Group(Tag::TOC.into(), self.entries) + TagNode::group(Tag::TOC, self.entries) } } diff --git a/crates/typst-pdf/src/tags/table.rs b/crates/typst-pdf/src/tags/table.rs index dbc52f990..362363294 100644 --- a/crates/typst-pdf/src/tags/table.rs +++ b/crates/typst-pdf/src/tags/table.rs @@ -107,7 +107,7 @@ impl TableCtx { // Table layouting ensures that there are no overlapping cells, and that // any gaps left by the user are filled with empty cells. if self.rows.is_empty() { - return TagNode::Group(Tag::Table.with_summary(self.summary).into(), nodes); + return TagNode::group(Tag::Table.with_summary(self.summary), nodes); } let height = self.rows.len(); let width = self.rows[0].len(); @@ -197,7 +197,7 @@ impl TableCtx { }) .collect(); - let row = TagNode::Group(Tag::TR.into(), row_nodes); + let row = TagNode::group(Tag::TR, row_nodes); // Push the `TR` tags directly. if !gen_row_groups {