mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #4124 from cocoatomo/appropriate-footnote-warning_2
Re-arrange WARNING messages about reference inconsistencies (revised)
This commit is contained in:
commit
8486f106b0
@ -327,22 +327,38 @@ class Locale(SphinxTransform):
|
||||
|
||||
self.document.note_refname(new)
|
||||
|
||||
# refnamed footnote and citation should use original 'ids'.
|
||||
# refnamed footnote should use original 'ids'.
|
||||
def is_refnamed_footnote_ref(node):
|
||||
# type: (nodes.Node) -> bool
|
||||
footnote_ref_classes = (nodes.footnote_reference,
|
||||
nodes.citation_reference)
|
||||
return isinstance(node, footnote_ref_classes) and \
|
||||
return isinstance(node, nodes.footnote_reference) and \
|
||||
'refname' in node
|
||||
old_refs = node.traverse(is_refnamed_footnote_ref)
|
||||
new_refs = patch.traverse(is_refnamed_footnote_ref)
|
||||
old_foot_refs = node.traverse(is_refnamed_footnote_ref)
|
||||
new_foot_refs = patch.traverse(is_refnamed_footnote_ref)
|
||||
refname_ids_map = {}
|
||||
if len(old_refs) != len(new_refs):
|
||||
logger.warning('inconsistent references in translated message',
|
||||
if len(old_foot_refs) != len(new_foot_refs):
|
||||
logger.warning('inconsistent footnote references in translated message',
|
||||
location=node)
|
||||
for old in old_refs:
|
||||
for old in old_foot_refs:
|
||||
refname_ids_map[old["refname"]] = old["ids"]
|
||||
for new in new_refs:
|
||||
for new in new_foot_refs:
|
||||
refname = new["refname"]
|
||||
if refname in refname_ids_map:
|
||||
new["ids"] = refname_ids_map[refname]
|
||||
|
||||
# citation should use original 'ids'.
|
||||
def is_citation_ref(node):
|
||||
# type: (nodes.Node) -> bool
|
||||
return isinstance(node, nodes.citation_reference) and \
|
||||
'refname' in node
|
||||
old_cite_refs = node.traverse(is_citation_ref)
|
||||
new_cite_refs = patch.traverse(is_citation_ref)
|
||||
refname_ids_map = {}
|
||||
if len(old_cite_refs) != len(new_cite_refs):
|
||||
logger.warning('inconsistent citation references in translated message',
|
||||
location=node)
|
||||
for old in old_cite_refs:
|
||||
refname_ids_map[old["refname"]] = old["ids"]
|
||||
for new in new_cite_refs:
|
||||
refname = new["refname"]
|
||||
if refname in refname_ids_map:
|
||||
new["ids"] = refname_ids_map[refname]
|
||||
|
@ -19,8 +19,8 @@ msgstr ""
|
||||
msgid "i18n with refs inconsistency"
|
||||
msgstr "I18N WITH REFS INCONSISTENCY"
|
||||
|
||||
msgid "[100]_ for [#]_ footnote [ref2]_."
|
||||
msgstr "FOR FOOTNOTE [ref2]_."
|
||||
msgid "[100]_ for [#]_ citation [ref2]_."
|
||||
msgstr "FOR CITATION [ref3]_."
|
||||
|
||||
msgid "for reference_."
|
||||
msgstr "reference_ FOR reference_."
|
||||
@ -31,8 +31,8 @@ msgstr "ORPHAN REFERENCE: `I18N WITH REFS INCONSISTENCY`_."
|
||||
msgid "This is a auto numbered footnote."
|
||||
msgstr "THIS IS A AUTO NUMBERED FOOTNOTE."
|
||||
|
||||
msgid "This is a named footnote."
|
||||
msgstr "THIS IS A NAMED FOOTNOTE."
|
||||
msgid "This is a citation."
|
||||
msgstr "THIS IS A CITATION."
|
||||
|
||||
msgid "This is a numbered footnote."
|
||||
msgstr "THIS IS A NUMBERED FOOTNOTE."
|
||||
|
@ -3,11 +3,11 @@
|
||||
i18n with refs inconsistency
|
||||
=============================
|
||||
|
||||
* [100]_ for [#]_ footnote [ref2]_.
|
||||
* [100]_ for [#]_ citation [ref2]_.
|
||||
* for reference_.
|
||||
* normal text.
|
||||
|
||||
.. [#] This is a auto numbered footnote.
|
||||
.. [ref2] This is a named footnote.
|
||||
.. [ref2] This is a citation.
|
||||
.. [100] This is a numbered footnote.
|
||||
.. _reference: http://www.example.com
|
||||
|
@ -182,11 +182,11 @@ def test_text_inconsistency_warnings(app, warning):
|
||||
result = (app.outdir / 'refs_inconsistency.txt').text(encoding='utf-8')
|
||||
expect = (u"I18N WITH REFS INCONSISTENCY"
|
||||
u"\n****************************\n"
|
||||
u"\n* FOR FOOTNOTE [ref2].\n"
|
||||
u"\n* FOR CITATION [ref3].\n"
|
||||
u"\n* reference FOR reference.\n"
|
||||
u"\n* ORPHAN REFERENCE: I18N WITH REFS INCONSISTENCY.\n"
|
||||
u"\n[1] THIS IS A AUTO NUMBERED FOOTNOTE.\n"
|
||||
u"\n[ref2] THIS IS A NAMED FOOTNOTE.\n"
|
||||
u"\n[ref2] THIS IS A CITATION.\n"
|
||||
u"\n[100] THIS IS A NUMBERED FOOTNOTE.\n")
|
||||
assert result == expect
|
||||
|
||||
@ -199,6 +199,10 @@ def test_text_inconsistency_warnings(app, warning):
|
||||
warning_fmt % 'references')
|
||||
assert_re_search(expected_warning_expr, warnings)
|
||||
|
||||
expected_citation_warning_expr = (
|
||||
u'.*/refs_inconsistency.txt:\\d+: WARNING: Citation \[ref2\] is not referenced.\n' +
|
||||
u'.*/refs_inconsistency.txt:\\d+: WARNING: citation not found: ref3')
|
||||
assert_re_search(expected_citation_warning_expr, warnings)
|
||||
|
||||
@sphinx_intl
|
||||
@pytest.mark.sphinx('text')
|
||||
|
Loading…
Reference in New Issue
Block a user