mirror of
https://github.com/typst/typst
synced 2025-07-27 06:17:53 +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 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".
|
||||
|
@ -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))
|
||||
|
@ -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)
|
||||
}
|
||||
)+
|
||||
}
|
||||
|
@ -6,3 +6,4 @@ heading = الفصل
|
||||
outline = المحتويات
|
||||
raw = قائمة
|
||||
page = صفحة
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Раздел
|
||||
outline = Съдържание
|
||||
raw = Приложение
|
||||
page = стр.
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Secció
|
||||
outline = Índex
|
||||
raw = Llistat
|
||||
page = pàgina
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Kapitola
|
||||
outline = Obsah
|
||||
raw = Výpis
|
||||
page = strana
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Afsnit
|
||||
outline = Indhold
|
||||
raw = Liste
|
||||
page = side
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Abschnitt
|
||||
outline = Inhaltsverzeichnis
|
||||
raw = Listing
|
||||
page = Seite
|
||||
footnote = Fußnote
|
||||
|
@ -5,3 +5,4 @@ bibliography = Βιβλιογραφία
|
||||
heading = Κεφάλαιο
|
||||
outline = Περιεχόμενα
|
||||
raw = Παράθεση
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Section
|
||||
outline = Contents
|
||||
raw = Listing
|
||||
page = page
|
||||
footnote = Footnote
|
||||
|
@ -6,3 +6,4 @@ heading = Sección
|
||||
outline = Índice
|
||||
raw = Listado
|
||||
page = página
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Peatükk
|
||||
outline = Sisukord
|
||||
raw = List
|
||||
page = lk.
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Atala
|
||||
outline = Aurkibidea
|
||||
raw = Kodea
|
||||
page = orria
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Osio
|
||||
outline = Sisällys
|
||||
raw = Esimerkki
|
||||
page = sivu
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Chapitre
|
||||
outline = Table des matières
|
||||
raw = Liste
|
||||
page = page
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Sección
|
||||
outline = Índice
|
||||
raw = Listado
|
||||
page = páxina
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = חלק
|
||||
outline = תוכן עניינים
|
||||
raw = קטע מקור
|
||||
page = עמוד
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Odjeljak
|
||||
outline = Sadržaj
|
||||
raw = Kôd
|
||||
page = str.
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Fejezet
|
||||
outline = Tartalomjegyzék
|
||||
# raw =
|
||||
page = oldal
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Bagian
|
||||
outline = Daftar Isi
|
||||
raw = Kode
|
||||
page = halaman
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Kafli
|
||||
outline = Efnisyfirlit
|
||||
raw = Sýnishorn
|
||||
page = blaðsíða
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Sezione
|
||||
outline = Indice
|
||||
raw = Codice
|
||||
page = pag.
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = 節
|
||||
outline = 目次
|
||||
raw = リスト
|
||||
page = ページ
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Caput
|
||||
outline = Index capitum
|
||||
raw = Exemplum
|
||||
page = charta
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Sadaļa
|
||||
outline = Saturs
|
||||
raw = Saraksts
|
||||
page = lpp.
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Kapittel
|
||||
outline = Innhold
|
||||
raw = Utskrift
|
||||
page = side
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Hoofdstuk
|
||||
outline = Inhoudsopgave
|
||||
raw = Listing
|
||||
page = pagina
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Kapittel
|
||||
outline = Innhald
|
||||
raw = Utskrift
|
||||
page = side
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Sekcja
|
||||
outline = Spis treści
|
||||
raw = Program
|
||||
page = strona
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Secção
|
||||
outline = Índice
|
||||
# raw =
|
||||
page = página
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Seção
|
||||
outline = Sumário
|
||||
raw = Listagem
|
||||
page = página
|
||||
# footnote =
|
||||
|
@ -7,3 +7,4 @@ outline = Cuprins
|
||||
# may be wrong
|
||||
raw = Listă
|
||||
page = pagina
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Раздел
|
||||
outline = Содержание
|
||||
raw = Листинг
|
||||
page = с.
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Poglavje
|
||||
outline = Kazalo
|
||||
raw = Program
|
||||
page = stran
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Kapitull
|
||||
outline = Përmbajtja
|
||||
raw = List
|
||||
page = faqe
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Поглавље
|
||||
outline = Садржај
|
||||
raw = Програм
|
||||
page = страна
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Avsnitt
|
||||
outline = Innehåll
|
||||
raw = Kodlistning
|
||||
page = sida
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Seksyon
|
||||
outline = Talaan ng mga Nilalaman
|
||||
raw = Listahan
|
||||
# page =
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Bölüm
|
||||
outline = İçindekiler
|
||||
raw = Liste
|
||||
page = sayfa
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = Розділ
|
||||
outline = Зміст
|
||||
raw = Лістинг
|
||||
page = c.
|
||||
# footnote =
|
||||
|
@ -7,3 +7,4 @@ outline = Mục lục
|
||||
# may be wrong
|
||||
raw = Chương trình
|
||||
page = trang
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = 小節
|
||||
outline = 目錄
|
||||
raw = 程式
|
||||
# page =
|
||||
# footnote =
|
||||
|
@ -6,3 +6,4 @@ heading = 小节
|
||||
outline = 目录
|
||||
raw = 代码
|
||||
# page =
|
||||
# footnote =
|
||||
|
Loading…
x
Reference in New Issue
Block a user