mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #7226 from tk0miya/7220_main_indexentries
Fix #7220: genindex: "main" index entries are not shown at first
This commit is contained in:
commit
dfaff26688
1
CHANGES
1
CHANGES
@ -63,6 +63,7 @@ Features added
|
||||
``no-scaled-link`` class
|
||||
* #7144: Add CSS class indicating its domain for each desc node
|
||||
* #7211: latex: Use babel for Chinese document when using XeLaTeX
|
||||
* #7220: genindex: Show "main" index entries at first
|
||||
|
||||
Bugs fixed
|
||||
----------
|
||||
|
@ -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]:
|
||||
|
@ -112,6 +112,21 @@ def test_create_seealso_index(app):
|
||||
assert index[2] == ('S', [('Sphinx', [[], [('see also documentation tool', [])], None])])
|
||||
|
||||
|
||||
@pytest.mark.sphinx('dummy', freshenv=True)
|
||||
def test_create_main_index(app):
|
||||
text = (".. index:: !docutils\n"
|
||||
".. index:: docutils\n"
|
||||
".. index:: pip; install\n"
|
||||
".. index:: !pip; install\n")
|
||||
restructuredtext.parse(app, text)
|
||||
index = IndexEntries(app.env).create_index(app.builder)
|
||||
assert len(index) == 2
|
||||
assert index[0] == ('D', [('docutils', [[('main', '#index-0'),
|
||||
('', '#index-1')], [], None])])
|
||||
assert index[1] == ('P', [('pip', [[], [('install', [('main', '#index-3'),
|
||||
('', '#index-2')])], None])])
|
||||
|
||||
|
||||
@pytest.mark.sphinx('dummy', freshenv=True)
|
||||
def test_create_index_with_name(app):
|
||||
text = (".. index:: single: docutils\n"
|
||||
|
Loading…
Reference in New Issue
Block a user