Merge pull request #6231 from tk0miya/6230_glossary_term_id

Fix #6230: Inappropriate node_id has been generated by glossary directive
This commit is contained in:
Takeshi KOMIYA 2019-03-31 23:59:41 +09:00 committed by GitHub
commit 20c177c575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
----------
@ -57,6 +59,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')], [], ''])])