Fix #6230: Inappropriate node_id has been generated by glossary directive

This commit is contained in:
Takeshi KOMIYA 2019-03-31 16:14:51 +09:00
parent 3f8a336d3a
commit cda4642bc1
3 changed files with 9 additions and 1 deletions

View File

@ -9,6 +9,8 @@ Incompatible changes
* Ignore filenames without file extension given to ``Builder.build_specific()``
API directly
* #6230: The anchor of term in glossary directive is changed if it is consisted
by non-ASCII characters
Deprecated
----------
@ -56,6 +58,9 @@ Features added
Bugs fixed
----------
* #6230: Inappropriate node_id has been generated by glossary directive if term
is consisted by non-ASCII characters
Testing
--------

View File

@ -257,6 +257,9 @@ def make_glossary_term(env, textnodes, index_key, source, lineno, new_id=None):
termtext = term.astext()
if new_id is None:
new_id = nodes.make_id('term-' + termtext)
if new_id == 'term':
# the term is not good for node_id. Generate it by sequence number instead.
new_id = 'term-' + str(len(gloss_entries))
if new_id in gloss_entries:
new_id = 'term-' + str(len(gloss_entries))
gloss_entries.add(new_id)

View File

@ -120,4 +120,4 @@ def test_create_index_by_key(app):
assert len(index) == 3
assert index[0] == ('D', [('docutils', [[('main', '#term-docutils')], [], None])])
assert index[1] == ('P', [('Python', [[('main', '#term-python')], [], None])])
assert index[2] == ('', [('スフィンクス', [[('main', '#term')], [], ''])])
assert index[2] == ('', [('スフィンクス', [[('main', '#term-2')], [], ''])])