From cda4642bc1e1abd4d1f28fe8fceb70c385e4e900 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 31 Mar 2019 16:14:51 +0900 Subject: [PATCH] Fix #6230: Inappropriate node_id has been generated by glossary directive --- CHANGES | 5 +++++ sphinx/domains/std.py | 3 +++ tests/test_environment_indexentries.py | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 1acf3ba1c..94f539a38 100644 --- a/CHANGES +++ b/CHANGES @@ -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 -------- diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index 2cfb4ceaa..a26394eb2 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -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) diff --git a/tests/test_environment_indexentries.py b/tests/test_environment_indexentries.py index 5b7cc36ec..ec76acdc0 100644 --- a/tests/test_environment_indexentries.py +++ b/tests/test_environment_indexentries.py @@ -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')], [], 'ス'])])