|
9 | 9 | from docutils import nodes
|
10 | 10 | from docutils.transforms import Transform, Transformer
|
11 | 11 | from docutils.transforms.parts import ContentsFilter
|
| 12 | +from docutils.transforms.references import Footnotes |
12 | 13 | from docutils.transforms.universal import SmartQuotes
|
13 | 14 | from docutils.utils import normalize_language_tag
|
14 | 15 | from docutils.utils.smartquotes import smartchars
|
@@ -294,23 +295,40 @@ class UnreferencedFootnotesDetector(SphinxTransform):
|
294 | 295 | Detect unreferenced footnotes and emit warnings
|
295 | 296 | """
|
296 | 297 |
|
297 |
| - default_priority = 200 |
| 298 | + default_priority = Footnotes.default_priority + 2 |
298 | 299 |
|
299 | 300 | def apply(self, **kwargs: Any) -> None:
|
300 | 301 | for node in self.document.footnotes:
|
301 |
| - if node['names'] == []: |
302 |
| - # footnote having duplicated number. It is already warned at parser. |
303 |
| - pass |
304 |
| - elif node['names'][0] not in self.document.footnote_refs: |
305 |
| - logger.warning(__('Footnote [%s] is not referenced.'), node['names'][0], |
306 |
| - type='ref', subtype='footnote', |
307 |
| - location=node) |
308 |
| - |
| 302 | + # note we do not warn on duplicate footnotes here |
| 303 | + # (i.e. where the name has been moved to dupnames) |
| 304 | + # since this is already reported by docutils |
| 305 | + if not node['backrefs'] and node["names"]: |
| 306 | + logger.warning( |
| 307 | + __('Footnote [%s] is not referenced.'), |
| 308 | + node['names'][0] if node['names'] else node['dupnames'][0], |
| 309 | + type='ref', |
| 310 | + subtype='footnote', |
| 311 | + location=node |
| 312 | + ) |
| 313 | + for node in self.document.symbol_footnotes: |
| 314 | + if not node['backrefs']: |
| 315 | + logger.warning( |
| 316 | + __('Footnote [*] is not referenced.'), |
| 317 | + type='ref', |
| 318 | + subtype='footnote', |
| 319 | + location=node |
| 320 | + ) |
309 | 321 | for node in self.document.autofootnotes:
|
310 |
| - if not any(ref['auto'] == node['auto'] for ref in self.document.autofootnote_refs): |
311 |
| - logger.warning(__('Footnote [#] is not referenced.'), |
312 |
| - type='ref', subtype='footnote', |
313 |
| - location=node) |
| 322 | + # note we do not warn on duplicate footnotes here |
| 323 | + # (i.e. where the name has been moved to dupnames) |
| 324 | + # since this is already reported by docutils |
| 325 | + if not node['backrefs'] and node["names"]: |
| 326 | + logger.warning( |
| 327 | + __('Footnote [#] is not referenced.'), |
| 328 | + type='ref', |
| 329 | + subtype='footnote', |
| 330 | + location=node |
| 331 | + ) |
314 | 332 |
|
315 | 333 |
|
316 | 334 | class DoctestTransform(SphinxTransform):
|
|
0 commit comments