summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES1
-rw-r--r--sphinx/environment/adapters/indexentries.py14
-rw-r--r--tests/test_environment_indexentries.py6
3 files changed, 14 insertions, 7 deletions
diff --git a/CHANGES b/CHANGES
index 36e5cc77b..5f5782a83 100644
--- a/CHANGES
+++ b/CHANGES
@@ -65,6 +65,7 @@ Bugs fixed
* C and C++, removed ``noindex`` directive option as it did
nothing.
* #7619: Duplicated node IDs are generated if node has multiple IDs
+* #2050: Symbols sections are appeared twice in the index page
Testing
--------
diff --git a/sphinx/environment/adapters/indexentries.py b/sphinx/environment/adapters/indexentries.py
index 5af213932..b13ac97c3 100644
--- a/sphinx/environment/adapters/indexentries.py
+++ b/sphinx/environment/adapters/indexentries.py
@@ -98,9 +98,8 @@ class IndexEntries:
for subentry in indexentry[1].values():
subentry[0].sort(key=keyfunc0) # type: ignore
- # sort the index entries; put all symbols at the front, even those
- # following the letters in ASCII, this is where the chr(127) comes from
- def keyfunc(entry: Tuple[str, List]) -> Tuple[str, str]:
+ # sort the index entries
+ def keyfunc(entry: Tuple[str, List]) -> Tuple[Tuple[int, str], str]:
key, (void, void, category_key) = entry
if category_key:
# using specified category key to sort
@@ -108,11 +107,16 @@ class IndexEntries:
lckey = unicodedata.normalize('NFD', key.lower())
if lckey.startswith('\N{RIGHT-TO-LEFT MARK}'):
lckey = lckey[1:]
+
if lckey[0:1].isalpha() or lckey.startswith('_'):
- lckey = chr(127) + lckey
+ # put non-symbol characters at the folloing group (1)
+ sortkey = (1, lckey)
+ else:
+ # put symbols at the front of the index (0)
+ sortkey = (0, lckey)
# ensure a determinstic order *within* letters by also sorting on
# the entry itself
- return (lckey, entry[0])
+ return (sortkey, entry[0])
newlist = sorted(new.items(), key=keyfunc)
if group_entries:
diff --git a/tests/test_environment_indexentries.py b/tests/test_environment_indexentries.py
index 7f6003d54..c15226d85 100644
--- a/tests/test_environment_indexentries.py
+++ b/tests/test_environment_indexentries.py
@@ -25,12 +25,14 @@ def test_create_single_index(app):
".. index:: ёлка\n"
".. index:: ‏תירבע‎\n"
".. index:: 9-symbol\n"
- ".. index:: &-symbol\n")
+ ".. index:: &-symbol\n"
+ ".. index:: £100\n")
restructuredtext.parse(app, text)
index = IndexEntries(app.env).create_index(app.builder)
assert len(index) == 6
assert index[0] == ('Symbols', [('&-symbol', [[('', '#index-9')], [], None]),
- ('9-symbol', [[('', '#index-8')], [], None])])
+ ('9-symbol', [[('', '#index-8')], [], None]),
+ ('£100', [[('', '#index-10')], [], None])])
assert index[1] == ('D', [('docutils', [[('', '#index-0')], [], None])])
assert index[2] == ('P', [('pip', [[], [('install', [('', '#index-2')]),
('upgrade', [('', '#index-3')])], None]),