-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rst] Improve unreferenced footnote warnings (#12730)
The previous `UnreferencedFootnotesDetector` transform was untested and missed warnings for a number of cases. This commit adds a test, to cover a reasonable range of scenarios, then changes how the detection works to pass this test. The transform now runs just after the docutils `Footnote` resolution transform (changing its priority from 200 to 622) then simply check for any footnotes without "back-references".
- Loading branch information
1 parent
df871ab
commit 05cc39d
Showing
3 changed files
with
76 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Test the ``UnreferencedFootnotesDetector`` transform.""" | ||
|
||
from pathlib import Path | ||
|
||
from sphinx.testing.util import SphinxTestApp | ||
from sphinx.util.console import strip_colors | ||
|
||
|
||
def test_warnings(make_app: type[SphinxTestApp], tmp_path: Path) -> None: | ||
"""Test that warnings are emitted for unreferenced footnotes.""" | ||
tmp_path.joinpath("conf.py").touch() | ||
tmp_path.joinpath("index.rst").write_text( | ||
""" | ||
Title | ||
===== | ||
[1]_ [#label2]_ | ||
.. [1] This is a normal footnote. | ||
.. [2] This is a normal footnote. | ||
.. [2] This is a normal footnote. | ||
.. [3] This is a normal footnote. | ||
.. [*] This is a symbol footnote. | ||
.. [#] This is an auto-numbered footnote. | ||
.. [#label1] This is an auto-numbered footnote with a label. | ||
.. [#label1] This is an auto-numbered footnote with a label. | ||
.. [#label2] This is an auto-numbered footnote with a label. | ||
""", encoding="utf8" | ||
) | ||
app = make_app(srcdir=tmp_path) | ||
app.build() | ||
warnings = strip_colors(app.warning.getvalue()).replace(str(tmp_path / "index.rst"), "source/index.rst") | ||
print(warnings) | ||
assert warnings.strip() == """ | ||
source/index.rst:8: WARNING: Duplicate explicit target name: "2". [docutils] | ||
source/index.rst:13: WARNING: Duplicate explicit target name: "label1". [docutils] | ||
source/index.rst:9: WARNING: Footnote [3] is not referenced. [ref.footnote] | ||
source/index.rst:10: WARNING: Footnote [*] is not referenced. [ref.footnote] | ||
source/index.rst:11: WARNING: Footnote [#] is not referenced. [ref.footnote] | ||
""".strip() |