refactor: use TagNode::group function

This commit is contained in:
Tobias Schmitz 2025-07-30 18:40:45 +02:00
parent 0e7d1f10ba
commit d9356abb39
No known key found for this signature in database
4 changed files with 18 additions and 18 deletions

View File

@ -68,7 +68,7 @@ impl ListCtx {
} }
pub(crate) fn push_bib_entry(&mut self, nodes: Vec<TagNode>) { pub(crate) fn push_bib_entry(&mut self, nodes: Vec<TagNode>) {
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. // Bibliography lists cannot be nested, but may be missing labels.
if let Some(item) = self.items.last_mut().filter(|item| item.body.is_none()) { if let Some(item) = self.items.last_mut().filter(|item| item.body.is_none()) {
item.body = Some(nodes); item.body = Some(nodes);
@ -83,17 +83,17 @@ impl ListCtx {
pub(crate) fn build_list(self, mut nodes: Vec<TagNode>) -> TagNode { pub(crate) fn build_list(self, mut nodes: Vec<TagNode>) -> TagNode {
for item in self.items.into_iter() { for item in self.items.into_iter() {
nodes.push(TagNode::Group( nodes.push(TagNode::group(
Tag::LI.into(), Tag::LI,
vec![ vec![
TagNode::Group(Tag::Lbl.into(), item.label), TagNode::group(Tag::Lbl, item.label),
TagNode::Group(Tag::LBody.into(), item.body.unwrap_or_default()), TagNode::group(Tag::LBody, item.body.unwrap_or_default()),
], ],
)); ));
if let Some(sub_list) = item.sub_list { if let Some(sub_list) = item.sub_list {
nodes.push(sub_list); nodes.push(sub_list);
} }
} }
TagNode::Group(Tag::L(self.numbering).into(), nodes) TagNode::group(Tag::L(self.numbering), nodes)
} }
} }

View File

@ -340,7 +340,7 @@ fn pop_stack(gc: &mut GlobalContext, entry: StackEntry) {
// PDF/UA compliance of the structure hierarchy is checked // PDF/UA compliance of the structure hierarchy is checked
// elsewhere. While this doesn't make a lot of sense, just // elsewhere. While this doesn't make a lot of sense, just
// avoid crashing here. // avoid crashing here.
gc.tags.push(TagNode::Group(Tag::TOCI.into(), entry.nodes)); gc.tags.push(TagNode::group(Tag::TOCI, entry.nodes));
return; return;
}; };
@ -354,7 +354,7 @@ fn pop_stack(gc: &mut GlobalContext, entry: StackEntry) {
// elsewhere. While this doesn't make a lot of sense, just // elsewhere. While this doesn't make a lot of sense, just
// avoid crashing here. // avoid crashing here.
let tag = Tag::TD.with_location(Some(cell.span().into_raw())); 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; return;
}; };
@ -379,19 +379,19 @@ fn pop_stack(gc: &mut GlobalContext, entry: StackEntry) {
} }
StackEntryKind::Figure(ctx) => { StackEntryKind::Figure(ctx) => {
let tag = Tag::Figure(ctx.alt).with_bbox(ctx.bbox.get()); 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) => { StackEntryKind::Formula(ctx) => {
let tag = Tag::Formula(ctx.alt).with_bbox(ctx.bbox.get()); 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) => { StackEntryKind::Link(_, link) => {
let alt = link.alt.as_ref().map(EcoString::to_string); let alt = link.alt.as_ref().map(EcoString::to_string);
let tag = Tag::Link.with_alt_text(alt); 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. // Wrap link in reference tag, if it's not a url.
if let Destination::Position(_) | Destination::Location(_) = link.dest { if let Destination::Position(_) | Destination::Location(_) = link.dest {
node = TagNode::Group(Tag::Reference.into(), vec![node]); node = TagNode::group(Tag::Reference, vec![node]);
} }
node node
} }
@ -411,7 +411,7 @@ fn pop_stack(gc: &mut GlobalContext, entry: StackEntry) {
StackEntryKind::FootnoteEntry(footnote_loc) => { StackEntryKind::FootnoteEntry(footnote_loc) => {
// Store footnotes separately so they can be inserted directly after // Store footnotes separately so they can be inserted directly after
// the footnote reference in the reading order. // 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()); let ctx = gc.tags.footnotes.entry(footnote_loc).or_insert(FootnoteCtx::new());
ctx.entry = Some(tag); ctx.entry = Some(tag);
return; return;

View File

@ -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); self.push(outline_nodes, section_entry);
} }
@ -49,7 +49,7 @@ impl OutlineCtx {
while !self.stack.is_empty() { while !self.stack.is_empty() {
self.finish_section(&mut outline_nodes); 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 { fn into_tag(self) -> TagNode {
TagNode::Group(Tag::TOC.into(), self.entries) TagNode::group(Tag::TOC, self.entries)
} }
} }

View File

@ -107,7 +107,7 @@ impl TableCtx {
// Table layouting ensures that there are no overlapping cells, and that // Table layouting ensures that there are no overlapping cells, and that
// any gaps left by the user are filled with empty cells. // any gaps left by the user are filled with empty cells.
if self.rows.is_empty() { 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 height = self.rows.len();
let width = self.rows[0].len(); let width = self.rows[0].len();
@ -197,7 +197,7 @@ impl TableCtx {
}) })
.collect(); .collect();
let row = TagNode::Group(Tag::TR.into(), row_nodes); let row = TagNode::group(Tag::TR, row_nodes);
// Push the `TR` tags directly. // Push the `TR` tags directly.
if !gen_row_groups { if !gen_row_groups {