feat: generate tags for footnotes

This commit is contained in:
Tobias Schmitz 2025-07-15 16:54:15 +02:00
parent 451b0815ff
commit 728d37efa0
No known key found for this signature in database
2 changed files with 10 additions and 10 deletions

View File

@ -394,11 +394,11 @@ const FOOTNOTE_RULE: ShowFn<FootnoteElem> = |elem, engine, styles| {
let numbering = elem.numbering.get_ref(styles); let numbering = elem.numbering.get_ref(styles);
let counter = Counter::of(FootnoteElem::ELEM); let counter = Counter::of(FootnoteElem::ELEM);
let num = counter.display_at_loc(engine, loc, styles, numbering)?; let num = counter.display_at_loc(engine, loc, styles, numbering)?;
let sup = SuperElem::new(num).pack().spanned(span); let alt = num.plain_text();
let sup = PdfMarkerTag::Label(SuperElem::new(num).pack().spanned(span));
let loc = loc.variant(1); let loc = loc.variant(1);
// Add zero-width weak spacing to make the footnote "sticky". // Add zero-width weak spacing to make the footnote "sticky".
// TODO(accessibility): generate alt text Ok(HElem::hole().pack() + sup.linked(Destination::Location(loc), Some(alt)))
Ok(HElem::hole().pack() + sup.linked(Destination::Location(loc), None))
}; };
const FOOTNOTE_ENTRY_RULE: ShowFn<FootnoteEntry> = |elem, engine, styles| { const FOOTNOTE_ENTRY_RULE: ShowFn<FootnoteEntry> = |elem, engine, styles| {
@ -415,11 +415,9 @@ const FOOTNOTE_ENTRY_RULE: ShowFn<FootnoteEntry> = |elem, engine, styles| {
}; };
let num = counter.display_at_loc(engine, loc, styles, numbering)?; let num = counter.display_at_loc(engine, loc, styles, numbering)?;
let sup = SuperElem::new(num) let alt = num.plain_text();
.pack() let sup = PdfMarkerTag::Label(SuperElem::new(num).pack().spanned(span))
.spanned(span) .linked(Destination::Location(loc), Some(alt))
// TODO(accessibility): generate alt text
.linked(Destination::Location(loc), None)
.located(loc.variant(1)); .located(loc.variant(1));
Ok(Content::sequence([ Ok(Content::sequence([

View File

@ -17,8 +17,8 @@ use typst_library::foundations::{
use typst_library::introspection::Location; use typst_library::introspection::Location;
use typst_library::layout::RepeatElem; use typst_library::layout::RepeatElem;
use typst_library::model::{ use typst_library::model::{
Destination, EnumElem, FigureCaption, FigureElem, HeadingElem, ListElem, Outlinable, Destination, EnumElem, FigureCaption, FigureElem, FootnoteEntry, HeadingElem,
OutlineEntry, TableCell, TableElem, TermsElem, ListElem, Outlinable, OutlineEntry, TableCell, TableElem, TermsElem,
}; };
use typst_library::pdf::{ArtifactElem, ArtifactKind, PdfMarkerTag, PdfMarkerTagKind}; use typst_library::pdf::{ArtifactElem, ArtifactKind, PdfMarkerTag, PdfMarkerTagKind};
use typst_library::visualize::ImageElem; use typst_library::visualize::ImageElem;
@ -141,6 +141,8 @@ pub(crate) fn handle_start(
let link_id = gc.tags.next_link_id(); let link_id = gc.tags.next_link_id();
push_stack(gc, loc, StackEntryKind::Link(link_id, link.clone()))?; push_stack(gc, loc, StackEntryKind::Link(link_id, link.clone()))?;
return Ok(()); return Ok(());
} else if let Some(_) = elem.to_packed::<FootnoteEntry>() {
TagKind::Note.into()
} else { } else {
return Ok(()); return Ok(());
}; };