Merge pull request #5571 from tk0miya/3002_i18n_duplicated_ids

Fix #3002: i18n: multiple footnote_references referring same footnote causes duplicated node_ids
This commit is contained in:
Takeshi KOMIYA 2018-11-01 01:23:34 +09:00 committed by GitHub
commit d9ee41b86a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 12 deletions

View File

@ -32,6 +32,8 @@ Bugs fixed
* #5419: incompatible math_block node has been generated * #5419: incompatible math_block node has been generated
* #5548: Fix ensuredir() in case of pre-existing file * #5548: Fix ensuredir() in case of pre-existing file
* #5549: graphviz Correctly deal with non-existing static dir * #5549: graphviz Correctly deal with non-existing static dir
* #3002: i18n: multiple footnote_references referring same footnote causes
duplicated node_ids
Testing Testing
-------- --------

View File

@ -364,7 +364,7 @@ class Locale(SphinxTransform):
'refname' in node 'refname' in node
old_foot_refs = node.traverse(is_refnamed_footnote_ref) old_foot_refs = node.traverse(is_refnamed_footnote_ref)
new_foot_refs = patch.traverse(is_refnamed_footnote_ref) new_foot_refs = patch.traverse(is_refnamed_footnote_ref)
refname_ids_map = {} refname_ids_map = {} # type: Dict[unicode, List[unicode]]
if len(old_foot_refs) != len(new_foot_refs): if len(old_foot_refs) != len(new_foot_refs):
old_foot_ref_rawsources = [ref.rawsource for ref in old_foot_refs] old_foot_ref_rawsources = [ref.rawsource for ref in old_foot_refs]
new_foot_ref_rawsources = [ref.rawsource for ref in new_foot_refs] new_foot_ref_rawsources = [ref.rawsource for ref in new_foot_refs]
@ -373,11 +373,11 @@ class Locale(SphinxTransform):
.format(old_foot_ref_rawsources, new_foot_ref_rawsources), .format(old_foot_ref_rawsources, new_foot_ref_rawsources),
location=node) location=node)
for old in old_foot_refs: for old in old_foot_refs:
refname_ids_map[old["refname"]] = old["ids"] refname_ids_map.setdefault(old["refname"], []).append(old["ids"])
for new in new_foot_refs: for new in new_foot_refs:
refname = new["refname"] refname = new["refname"]
if refname in refname_ids_map: if refname_ids_map.get(refname):
new["ids"] = refname_ids_map[refname] new["ids"] = refname_ids_map[refname].pop(0)
# citation should use original 'ids'. # citation should use original 'ids'.
def is_citation_ref(node): def is_citation_ref(node):
@ -395,11 +395,11 @@ class Locale(SphinxTransform):
.format(old_cite_ref_rawsources, new_cite_ref_rawsources), .format(old_cite_ref_rawsources, new_cite_ref_rawsources),
location=node) location=node)
for old in old_cite_refs: for old in old_cite_refs:
refname_ids_map[old["refname"]] = old["ids"] refname_ids_map.setdefault(old["refname"], []).append(old["ids"])
for new in new_cite_refs: for new in new_cite_refs:
refname = new["refname"] refname = new["refname"]
if refname in refname_ids_map: if refname_ids_map.get(refname):
new["ids"] = refname_ids_map[refname] new["ids"] = refname_ids_map[refname].pop()
# Original pending_xref['reftarget'] contain not-translated # Original pending_xref['reftarget'] contain not-translated
# target name, new pending_xref must use original one. # target name, new pending_xref must use original one.

View File

@ -20,7 +20,9 @@ msgid "i18n with Footnote"
msgstr "I18N WITH FOOTNOTE" msgstr "I18N WITH FOOTNOTE"
msgid "[100]_ Contents [#]_ for `i18n with Footnote`_ [ref]_ [#named]_ [*]_. " msgid "[100]_ Contents [#]_ for `i18n with Footnote`_ [ref]_ [#named]_ [*]_. "
"second footnote_ref [100]_."
msgstr "`I18N WITH FOOTNOTE`_ INCLUDE THIS CONTENTS [#named]_ [ref]_ [#]_ [100]_ [*]_. " msgstr "`I18N WITH FOOTNOTE`_ INCLUDE THIS CONTENTS [#named]_ [ref]_ [#]_ [100]_ [*]_. "
"SECOND FOOTNOTE_REF [100]_."
msgid "This is a auto numbered footnote." msgid "This is a auto numbered footnote."
msgstr "THIS IS A AUTO NUMBERED FOOTNOTE." msgstr "THIS IS A AUTO NUMBERED FOOTNOTE."

View File

@ -5,6 +5,7 @@ i18n with Footnote
.. #955 cant-build-html-with-footnotes-when-using .. #955 cant-build-html-with-footnotes-when-using
[100]_ Contents [#]_ for `i18n with Footnote`_ [ref]_ [#named]_ [*]_. [100]_ Contents [#]_ for `i18n with Footnote`_ [ref]_ [#named]_ [*]_.
second footnote_ref [100]_.
.. [#] This is a auto numbered footnote. .. [#] This is a auto numbered footnote.
.. [ref] This is a named footnote. .. [ref] This is a named footnote.

View File

@ -794,9 +794,13 @@ def test_xml_footnotes(app, warning):
assert_elem( assert_elem(
para0[0], para0[0],
['I18N WITH FOOTNOTE', 'INCLUDE THIS CONTENTS', ['I18N WITH FOOTNOTE', 'INCLUDE THIS CONTENTS',
'2', '[ref]', '1', '100', '*', '.'], '2', '[ref]', '1', '100', '*', '. SECOND FOOTNOTE_REF', '100', '.'],
['i18n-with-footnote', 'ref']) ['i18n-with-footnote', 'ref'])
# check node_id for footnote_references which refer same footnote (refs: #3002)
assert para0[0][4].text == para0[0][6].text == '100'
assert para0[0][4].attrib['ids'] != para0[0][6].attrib['ids']
footnote0 = secs[0].findall('footnote') footnote0 = secs[0].findall('footnote')
assert_elem( assert_elem(
footnote0[0], footnote0[0],
@ -848,8 +852,8 @@ def test_xml_footnote_backlinks(app):
footnote0 = secs[0].findall('footnote') footnote0 = secs[0].findall('footnote')
for footnote in footnote0: for footnote in footnote0:
ids = footnote.attrib.get('ids') ids = footnote.attrib.get('ids')
backrefs = footnote.attrib.get('backrefs') backrefs = footnote.attrib.get('backrefs').split()
assert refid2id[ids] == backrefs assert refid2id[ids] in backrefs
@sphinx_intl @sphinx_intl