Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-02-29 08:41:00 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-02-29 12:51:09 +0300
commit0132aa527fc1b9d53c986e633f5ed62ad0775453 (patch)
tree034c1452eef8918526d57bdc45565c27c466a76d /sphinx/environment
parent093d24ede0d15e01662f4543d7be44eb817eee22 (diff)
Close #7220: genindex: Show "main" index entries at first
Diffstat (limited to 'sphinx/environment')
-rw-r--r--sphinx/environment/adapters/indexentries.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/sphinx/environment/adapters/indexentries.py b/sphinx/environment/adapters/indexentries.py
index 1d135bd32..dbc94f846 100644
--- a/sphinx/environment/adapters/indexentries.py
+++ b/sphinx/environment/adapters/indexentries.py
@@ -7,7 +7,7 @@
:copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
-import bisect
+
import re
import unicodedata
from itertools import groupby
@@ -52,8 +52,7 @@ class IndexEntries:
except NoUri:
pass
else:
- # maintain links in sorted/deterministic order
- bisect.insort(entry[0], (main, uri))
+ entry[0].append((main, uri))
domain = cast(IndexDomain, self.env.get_domain('index'))
for fn, entries in domain.entries.items():
@@ -89,6 +88,16 @@ class IndexEntries:
except ValueError as err:
logger.warning(str(err), location=fn)
+ # sort the index entries for same keyword.
+ def keyfunc0(entry: Tuple[str, str]) -> Tuple[bool, str]:
+ main, uri = entry
+ return (not main, uri) # show main entries at first
+
+ for indexentry in new.values():
+ indexentry[0] = sorted(indexentry[0], key=keyfunc0)
+ for subentry in indexentry[1].values():
+ subentry[0] = sorted(subentry[0], 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]: