feat: better alt text for footnote links

This commit is contained in:
Tobias Schmitz 2025-07-16 13:57:41 +02:00
parent 153c5d3a4a
commit bf75ab858d
No known key found for this signature in database
44 changed files with 55 additions and 3 deletions

View File

@ -384,7 +384,7 @@ const FOOTNOTE_RULE: ShowFn<FootnoteElem> = |elem, engine, styles| {
let numbering = elem.numbering.get_ref(styles);
let counter = Counter::of(FootnoteElem::ELEM);
let num = counter.display_at_loc(engine, loc, styles, numbering)?;
let alt = num.plain_text();
let alt = FootnoteElem::alt_text(styles, &num.plain_text());
let sup = PdfMarkerTag::Label(SuperElem::new(num).pack().spanned(span));
let loc = loc.variant(1);
// Add zero-width weak spacing to make the footnote "sticky".

View File

@ -1,6 +1,7 @@
use std::num::NonZeroUsize;
use std::str::FromStr;
use ecow::{eco_format, EcoString};
use typst_utils::NonZeroExt;
use crate::diag::{bail, StrResult};
@ -12,7 +13,7 @@ use crate::foundations::{
use crate::introspection::{Count, CounterUpdate, Locatable, Location};
use crate::layout::{Abs, Em, Length, Ratio};
use crate::model::{Numbering, NumberingPattern, ParElem};
use crate::text::{TextElem, TextSize};
use crate::text::{LocalName, TextElem, TextSize};
use crate::visualize::{LineElem, Stroke};
/// A footnote.
@ -82,7 +83,16 @@ impl FootnoteElem {
type FootnoteEntry;
}
impl LocalName for Packed<FootnoteElem> {
const KEY: &'static str = "footnote";
}
impl FootnoteElem {
pub fn alt_text(styles: StyleChain, num: &str) -> EcoString {
let local_name = Packed::<FootnoteElem>::local_name_in(styles);
eco_format!("{local_name} {num}")
}
/// Creates a new footnote that the passed content as its body.
pub fn with_content(content: Content) -> Self {
Self::new(FootnoteBody::Content(content))

View File

@ -122,7 +122,8 @@ macro_rules! pdf_marker_tag {
#[doc = $doc]
#[allow(non_snake_case)]
pub fn $variant(body: Content) -> Content {
Self::new(PdfMarkerTagKind::$variant, body).pack()
let span = body.span();
Self::new(PdfMarkerTagKind::$variant, body).pack().spanned(span)
}
)+
}

View File

@ -6,3 +6,4 @@ heading = الفصل
outline = المحتويات
raw = قائمة
page = صفحة
# footnote =

View File

@ -6,3 +6,4 @@ heading = Раздел
outline = Съдържание
raw = Приложение
page = стр.
# footnote =

View File

@ -6,3 +6,4 @@ heading = Secció
outline = Índex
raw = Llistat
page = pàgina
# footnote =

View File

@ -6,3 +6,4 @@ heading = Kapitola
outline = Obsah
raw = Výpis
page = strana
# footnote =

View File

@ -6,3 +6,4 @@ heading = Afsnit
outline = Indhold
raw = Liste
page = side
# footnote =

View File

@ -6,3 +6,4 @@ heading = Abschnitt
outline = Inhaltsverzeichnis
raw = Listing
page = Seite
footnote = Fußnote

View File

@ -5,3 +5,4 @@ bibliography = Βιβλιογραφία
heading = Κεφάλαιο
outline = Περιεχόμενα
raw = Παράθεση
# footnote =

View File

@ -6,3 +6,4 @@ heading = Section
outline = Contents
raw = Listing
page = page
footnote = Footnote

View File

@ -6,3 +6,4 @@ heading = Sección
outline = Índice
raw = Listado
page = página
# footnote =

View File

@ -6,3 +6,4 @@ heading = Peatükk
outline = Sisukord
raw = List
page = lk.
# footnote =

View File

@ -6,3 +6,4 @@ heading = Atala
outline = Aurkibidea
raw = Kodea
page = orria
# footnote =

View File

@ -6,3 +6,4 @@ heading = Osio
outline = Sisällys
raw = Esimerkki
page = sivu
# footnote =

View File

@ -6,3 +6,4 @@ heading = Chapitre
outline = Table des matières
raw = Liste
page = page
# footnote =

View File

@ -6,3 +6,4 @@ heading = Sección
outline = Índice
raw = Listado
page = páxina
# footnote =

View File

@ -6,3 +6,4 @@ heading = חלק
outline = תוכן עניינים
raw = קטע מקור
page = עמוד
# footnote =

View File

@ -6,3 +6,4 @@ heading = Odjeljak
outline = Sadržaj
raw = Kôd
page = str.
# footnote =

View File

@ -6,3 +6,4 @@ heading = Fejezet
outline = Tartalomjegyzék
# raw =
page = oldal
# footnote =

View File

@ -6,3 +6,4 @@ heading = Bagian
outline = Daftar Isi
raw = Kode
page = halaman
# footnote =

View File

@ -6,3 +6,4 @@ heading = Kafli
outline = Efnisyfirlit
raw = Sýnishorn
page = blaðsíða
# footnote =

View File

@ -6,3 +6,4 @@ heading = Sezione
outline = Indice
raw = Codice
page = pag.
# footnote =

View File

@ -6,3 +6,4 @@ heading = 節
outline = 目次
raw = リスト
page = ページ
# footnote =

View File

@ -6,3 +6,4 @@ heading = Caput
outline = Index capitum
raw = Exemplum
page = charta
# footnote =

View File

@ -6,3 +6,4 @@ heading = Sadaļa
outline = Saturs
raw = Saraksts
page = lpp.
# footnote =

View File

@ -6,3 +6,4 @@ heading = Kapittel
outline = Innhold
raw = Utskrift
page = side
# footnote =

View File

@ -6,3 +6,4 @@ heading = Hoofdstuk
outline = Inhoudsopgave
raw = Listing
page = pagina
# footnote =

View File

@ -6,3 +6,4 @@ heading = Kapittel
outline = Innhald
raw = Utskrift
page = side
# footnote =

View File

@ -6,3 +6,4 @@ heading = Sekcja
outline = Spis treści
raw = Program
page = strona
# footnote =

View File

@ -6,3 +6,4 @@ heading = Secção
outline = Índice
# raw =
page = página
# footnote =

View File

@ -6,3 +6,4 @@ heading = Seção
outline = Sumário
raw = Listagem
page = página
# footnote =

View File

@ -7,3 +7,4 @@ outline = Cuprins
# may be wrong
raw = Listă
page = pagina
# footnote =

View File

@ -6,3 +6,4 @@ heading = Раздел
outline = Содержание
raw = Листинг
page = с.
# footnote =

View File

@ -6,3 +6,4 @@ heading = Poglavje
outline = Kazalo
raw = Program
page = stran
# footnote =

View File

@ -6,3 +6,4 @@ heading = Kapitull
outline = Përmbajtja
raw = List
page = faqe
# footnote =

View File

@ -6,3 +6,4 @@ heading = Поглавље
outline = Садржај
raw = Програм
page = страна
# footnote =

View File

@ -6,3 +6,4 @@ heading = Avsnitt
outline = Innehåll
raw = Kodlistning
page = sida
# footnote =

View File

@ -6,3 +6,4 @@ heading = Seksyon
outline = Talaan ng mga Nilalaman
raw = Listahan
# page =
# footnote =

View File

@ -6,3 +6,4 @@ heading = Bölüm
outline = İçindekiler
raw = Liste
page = sayfa
# footnote =

View File

@ -6,3 +6,4 @@ heading = Розділ
outline = Зміст
raw = Лістинг
page = c.
# footnote =

View File

@ -7,3 +7,4 @@ outline = Mục lục
# may be wrong
raw = Chương trình
page = trang
# footnote =

View File

@ -6,3 +6,4 @@ heading = 小節
outline = 目錄
raw = 程式
# page =
# footnote =

View File

@ -6,3 +6,4 @@ heading = 小节
outline = 目录
raw = 代码
# page =
# footnote =