mirror of
https://github.com/typst/typst
synced 2025-07-27 22:37:54 +08:00
feat: better alt text for footnote links
This commit is contained in:
parent
153c5d3a4a
commit
bf75ab858d
@ -384,7 +384,7 @@ 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 alt = num.plain_text();
|
let alt = FootnoteElem::alt_text(styles, &num.plain_text());
|
||||||
let sup = PdfMarkerTag::Label(SuperElem::new(num).pack().spanned(span));
|
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".
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use std::num::NonZeroUsize;
|
use std::num::NonZeroUsize;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use ecow::{eco_format, EcoString};
|
||||||
use typst_utils::NonZeroExt;
|
use typst_utils::NonZeroExt;
|
||||||
|
|
||||||
use crate::diag::{bail, StrResult};
|
use crate::diag::{bail, StrResult};
|
||||||
@ -12,7 +13,7 @@ use crate::foundations::{
|
|||||||
use crate::introspection::{Count, CounterUpdate, Locatable, Location};
|
use crate::introspection::{Count, CounterUpdate, Locatable, Location};
|
||||||
use crate::layout::{Abs, Em, Length, Ratio};
|
use crate::layout::{Abs, Em, Length, Ratio};
|
||||||
use crate::model::{Numbering, NumberingPattern, ParElem};
|
use crate::model::{Numbering, NumberingPattern, ParElem};
|
||||||
use crate::text::{TextElem, TextSize};
|
use crate::text::{LocalName, TextElem, TextSize};
|
||||||
use crate::visualize::{LineElem, Stroke};
|
use crate::visualize::{LineElem, Stroke};
|
||||||
|
|
||||||
/// A footnote.
|
/// A footnote.
|
||||||
@ -82,7 +83,16 @@ impl FootnoteElem {
|
|||||||
type FootnoteEntry;
|
type FootnoteEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl LocalName for Packed<FootnoteElem> {
|
||||||
|
const KEY: &'static str = "footnote";
|
||||||
|
}
|
||||||
|
|
||||||
impl FootnoteElem {
|
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.
|
/// Creates a new footnote that the passed content as its body.
|
||||||
pub fn with_content(content: Content) -> Self {
|
pub fn with_content(content: Content) -> Self {
|
||||||
Self::new(FootnoteBody::Content(content))
|
Self::new(FootnoteBody::Content(content))
|
||||||
|
@ -122,7 +122,8 @@ macro_rules! pdf_marker_tag {
|
|||||||
#[doc = $doc]
|
#[doc = $doc]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub fn $variant(body: Content) -> Content {
|
pub fn $variant(body: Content) -> Content {
|
||||||
Self::new(PdfMarkerTagKind::$variant, body).pack()
|
let span = body.span();
|
||||||
|
Self::new(PdfMarkerTagKind::$variant, body).pack().spanned(span)
|
||||||
}
|
}
|
||||||
)+
|
)+
|
||||||
}
|
}
|
||||||
|
@ -6,3 +6,4 @@ heading = الفصل
|
|||||||
outline = المحتويات
|
outline = المحتويات
|
||||||
raw = قائمة
|
raw = قائمة
|
||||||
page = صفحة
|
page = صفحة
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Раздел
|
|||||||
outline = Съдържание
|
outline = Съдържание
|
||||||
raw = Приложение
|
raw = Приложение
|
||||||
page = стр.
|
page = стр.
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Secció
|
|||||||
outline = Índex
|
outline = Índex
|
||||||
raw = Llistat
|
raw = Llistat
|
||||||
page = pàgina
|
page = pàgina
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Kapitola
|
|||||||
outline = Obsah
|
outline = Obsah
|
||||||
raw = Výpis
|
raw = Výpis
|
||||||
page = strana
|
page = strana
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Afsnit
|
|||||||
outline = Indhold
|
outline = Indhold
|
||||||
raw = Liste
|
raw = Liste
|
||||||
page = side
|
page = side
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Abschnitt
|
|||||||
outline = Inhaltsverzeichnis
|
outline = Inhaltsverzeichnis
|
||||||
raw = Listing
|
raw = Listing
|
||||||
page = Seite
|
page = Seite
|
||||||
|
footnote = Fußnote
|
||||||
|
@ -5,3 +5,4 @@ bibliography = Βιβλιογραφία
|
|||||||
heading = Κεφάλαιο
|
heading = Κεφάλαιο
|
||||||
outline = Περιεχόμενα
|
outline = Περιεχόμενα
|
||||||
raw = Παράθεση
|
raw = Παράθεση
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Section
|
|||||||
outline = Contents
|
outline = Contents
|
||||||
raw = Listing
|
raw = Listing
|
||||||
page = page
|
page = page
|
||||||
|
footnote = Footnote
|
||||||
|
@ -6,3 +6,4 @@ heading = Sección
|
|||||||
outline = Índice
|
outline = Índice
|
||||||
raw = Listado
|
raw = Listado
|
||||||
page = página
|
page = página
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Peatükk
|
|||||||
outline = Sisukord
|
outline = Sisukord
|
||||||
raw = List
|
raw = List
|
||||||
page = lk.
|
page = lk.
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Atala
|
|||||||
outline = Aurkibidea
|
outline = Aurkibidea
|
||||||
raw = Kodea
|
raw = Kodea
|
||||||
page = orria
|
page = orria
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Osio
|
|||||||
outline = Sisällys
|
outline = Sisällys
|
||||||
raw = Esimerkki
|
raw = Esimerkki
|
||||||
page = sivu
|
page = sivu
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Chapitre
|
|||||||
outline = Table des matières
|
outline = Table des matières
|
||||||
raw = Liste
|
raw = Liste
|
||||||
page = page
|
page = page
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Sección
|
|||||||
outline = Índice
|
outline = Índice
|
||||||
raw = Listado
|
raw = Listado
|
||||||
page = páxina
|
page = páxina
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = חלק
|
|||||||
outline = תוכן עניינים
|
outline = תוכן עניינים
|
||||||
raw = קטע מקור
|
raw = קטע מקור
|
||||||
page = עמוד
|
page = עמוד
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Odjeljak
|
|||||||
outline = Sadržaj
|
outline = Sadržaj
|
||||||
raw = Kôd
|
raw = Kôd
|
||||||
page = str.
|
page = str.
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Fejezet
|
|||||||
outline = Tartalomjegyzék
|
outline = Tartalomjegyzék
|
||||||
# raw =
|
# raw =
|
||||||
page = oldal
|
page = oldal
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Bagian
|
|||||||
outline = Daftar Isi
|
outline = Daftar Isi
|
||||||
raw = Kode
|
raw = Kode
|
||||||
page = halaman
|
page = halaman
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Kafli
|
|||||||
outline = Efnisyfirlit
|
outline = Efnisyfirlit
|
||||||
raw = Sýnishorn
|
raw = Sýnishorn
|
||||||
page = blaðsíða
|
page = blaðsíða
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Sezione
|
|||||||
outline = Indice
|
outline = Indice
|
||||||
raw = Codice
|
raw = Codice
|
||||||
page = pag.
|
page = pag.
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = 節
|
|||||||
outline = 目次
|
outline = 目次
|
||||||
raw = リスト
|
raw = リスト
|
||||||
page = ページ
|
page = ページ
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Caput
|
|||||||
outline = Index capitum
|
outline = Index capitum
|
||||||
raw = Exemplum
|
raw = Exemplum
|
||||||
page = charta
|
page = charta
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Sadaļa
|
|||||||
outline = Saturs
|
outline = Saturs
|
||||||
raw = Saraksts
|
raw = Saraksts
|
||||||
page = lpp.
|
page = lpp.
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Kapittel
|
|||||||
outline = Innhold
|
outline = Innhold
|
||||||
raw = Utskrift
|
raw = Utskrift
|
||||||
page = side
|
page = side
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Hoofdstuk
|
|||||||
outline = Inhoudsopgave
|
outline = Inhoudsopgave
|
||||||
raw = Listing
|
raw = Listing
|
||||||
page = pagina
|
page = pagina
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Kapittel
|
|||||||
outline = Innhald
|
outline = Innhald
|
||||||
raw = Utskrift
|
raw = Utskrift
|
||||||
page = side
|
page = side
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Sekcja
|
|||||||
outline = Spis treści
|
outline = Spis treści
|
||||||
raw = Program
|
raw = Program
|
||||||
page = strona
|
page = strona
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Secção
|
|||||||
outline = Índice
|
outline = Índice
|
||||||
# raw =
|
# raw =
|
||||||
page = página
|
page = página
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Seção
|
|||||||
outline = Sumário
|
outline = Sumário
|
||||||
raw = Listagem
|
raw = Listagem
|
||||||
page = página
|
page = página
|
||||||
|
# footnote =
|
||||||
|
@ -7,3 +7,4 @@ outline = Cuprins
|
|||||||
# may be wrong
|
# may be wrong
|
||||||
raw = Listă
|
raw = Listă
|
||||||
page = pagina
|
page = pagina
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Раздел
|
|||||||
outline = Содержание
|
outline = Содержание
|
||||||
raw = Листинг
|
raw = Листинг
|
||||||
page = с.
|
page = с.
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Poglavje
|
|||||||
outline = Kazalo
|
outline = Kazalo
|
||||||
raw = Program
|
raw = Program
|
||||||
page = stran
|
page = stran
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Kapitull
|
|||||||
outline = Përmbajtja
|
outline = Përmbajtja
|
||||||
raw = List
|
raw = List
|
||||||
page = faqe
|
page = faqe
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Поглавље
|
|||||||
outline = Садржај
|
outline = Садржај
|
||||||
raw = Програм
|
raw = Програм
|
||||||
page = страна
|
page = страна
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Avsnitt
|
|||||||
outline = Innehåll
|
outline = Innehåll
|
||||||
raw = Kodlistning
|
raw = Kodlistning
|
||||||
page = sida
|
page = sida
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Seksyon
|
|||||||
outline = Talaan ng mga Nilalaman
|
outline = Talaan ng mga Nilalaman
|
||||||
raw = Listahan
|
raw = Listahan
|
||||||
# page =
|
# page =
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Bölüm
|
|||||||
outline = İçindekiler
|
outline = İçindekiler
|
||||||
raw = Liste
|
raw = Liste
|
||||||
page = sayfa
|
page = sayfa
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = Розділ
|
|||||||
outline = Зміст
|
outline = Зміст
|
||||||
raw = Лістинг
|
raw = Лістинг
|
||||||
page = c.
|
page = c.
|
||||||
|
# footnote =
|
||||||
|
@ -7,3 +7,4 @@ outline = Mục lục
|
|||||||
# may be wrong
|
# may be wrong
|
||||||
raw = Chương trình
|
raw = Chương trình
|
||||||
page = trang
|
page = trang
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = 小節
|
|||||||
outline = 目錄
|
outline = 目錄
|
||||||
raw = 程式
|
raw = 程式
|
||||||
# page =
|
# page =
|
||||||
|
# footnote =
|
||||||
|
@ -6,3 +6,4 @@ heading = 小节
|
|||||||
outline = 目录
|
outline = 目录
|
||||||
raw = 代码
|
raw = 代码
|
||||||
# page =
|
# page =
|
||||||
|
# footnote =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user