Skip to content

Commit

Permalink
Merge pull request sphinx-doc#6563 from tk0miya/6561_glossary_hyperre…
Browse files Browse the repository at this point in the history
…r_for_alphanumeric_term

Fix sphinx-doc#6561: glossary: Wrong hyperlinks are generated for non alphanumeric terms
  • Loading branch information
tk0miya authored Jul 13, 2019
2 parents 7bfc8c9 + a252636 commit 0bc530f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Bugs fixed
each comma separated option
* #6549: sphinx-build: Escaped characters in error messages
* #6545: doctest comments not getting trimmed since Sphinx 1.8.0
* #6561: glossary: Wrong hyperlinks are generated for non alphanumeric terms

Testing
--------
Expand Down
6 changes: 3 additions & 3 deletions sphinx/domains/std.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ def make_glossary_term(env: "BuildEnvironment", textnodes: Iterable[Node], index
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))
new_id = 'term-%d' % env.new_serialno('glossary')
while new_id in gloss_entries:
new_id = 'term-%d' % env.new_serialno('glossary')
gloss_entries.add(new_id)

std = cast(StandardDomain, env.get_domain('std'))
Expand Down
11 changes: 11 additions & 0 deletions tests/test_domain_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@ def test_glossary_sorted(app):
[nodes.definition, nodes.paragraph, "description"])


def test_glossary_alphanumeric(app):
text = (".. glossary::\n"
"\n"
" 1\n"
" /\n")
restructuredtext.parse(app, text)
objects = list(app.env.get_domain("std").get_objects())
assert ("1", "1", "term", "index", "term-1", -1) in objects
assert ("/", "/", "term", "index", "term-0", -1) in objects


def test_cmdoption(app):
text = (".. program:: ls\n"
"\n"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_environment_indexentries.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,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-2')], [], 'ス'])])
assert index[2] == ('ス', [('スフィンクス', [[('main', '#term-0')], [], 'ス'])])

0 comments on commit 0bc530f

Please sign in to comment.