mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-02 18:27:37 +00:00

Multiple references to a single footnote is a part of GitHub Flavored
Markdown syntax (although not explicitly documented as well as regular
footnotes, it is implemented in GitHub's fork of CommonMark) and not
prohibited by rustdoc.
cf. <587a12bb54/test/extensions.txt (L762-L780)
>
However, using it makes multiple "sup" elements with the same "id"
attribute, which is invalid per the HTML specification.
Still, not only this is a valid GitHub Flavored Markdown syntax, this is
helpful on certain cases and actually tested (accidentally) in
tests/rustdoc/footnote-reference-in-footnote-def.rs.
This commit keeps track of the number of references per footnote and gives
unique ID to each reference. It also emits *all* back links from a footnote
to its references as "↩" (return symbol) plus a numeric list in superscript.
As a known limitation, it assumes that all references to a footnote are
rendered (this is not always true if a dangling footnote has one or more
references but considered a reasonable compromise).
Also note that, this commit is designed so that no HTML changes will occur
unless multiple references to a single footnote is actually used.
24 lines
763 B
Rust
24 lines
763 B
Rust
// This test ensures that multiple references to a single footnote and
|
|
// corresponding back links work as expected.
|
|
|
|
#![crate_name = "foo"]
|
|
|
|
//@ has 'foo/index.html'
|
|
//@ has - '//*[@class="docblock"]/p/sup[@id="fnref1"]/a[@href="#fn1"]' '1'
|
|
//@ has - '//*[@class="docblock"]/p/sup[@id="fnref2"]/a[@href="#fn2"]' '2'
|
|
//@ has - '//*[@class="docblock"]/p/sup[@id="fnref2-2"]/a[@href="#fn2"]' '2'
|
|
//@ has - '//li[@id="fn1"]/p' 'meow'
|
|
//@ has - '//li[@id="fn1"]/p/a[@href="#fnref1"]' '↩'
|
|
//@ has - '//li[@id="fn2"]/p' 'uwu'
|
|
//@ has - '//li[@id="fn2"]/p/a[@href="#fnref2"]/sup' '1'
|
|
//@ has - '//li[@id="fn2"]/p/sup/a[@href="#fnref2-2"]' '2'
|
|
|
|
//! # Footnote, references and back links
|
|
//!
|
|
//! Single: [^a].
|
|
//!
|
|
//! Double: [^b] [^b].
|
|
//!
|
|
//! [^a]: meow
|
|
//! [^b]: uwu
|