mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #2050: Symbols sections are appeared twice in the index page
Multibyte symbols are categorized to independent symbols section different to single byte symbols. This integrate them to a single section.
This commit is contained in:
parent
4ec6cbe341
commit
66da266441
1
CHANGES
1
CHANGES
@ -65,6 +65,7 @@ Bugs fixed
|
|||||||
* C and C++, removed ``noindex`` directive option as it did
|
* C and C++, removed ``noindex`` directive option as it did
|
||||||
nothing.
|
nothing.
|
||||||
* #7619: Duplicated node IDs are generated if node has multiple IDs
|
* #7619: Duplicated node IDs are generated if node has multiple IDs
|
||||||
|
* #2050: Symbols sections are appeared twice in the index page
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -98,9 +98,8 @@ class IndexEntries:
|
|||||||
for subentry in indexentry[1].values():
|
for subentry in indexentry[1].values():
|
||||||
subentry[0].sort(key=keyfunc0) # type: ignore
|
subentry[0].sort(key=keyfunc0) # type: ignore
|
||||||
|
|
||||||
# sort the index entries; put all symbols at the front, even those
|
# sort the index entries
|
||||||
# following the letters in ASCII, this is where the chr(127) comes from
|
def keyfunc(entry: Tuple[str, List]) -> Tuple[Tuple[int, str], str]:
|
||||||
def keyfunc(entry: Tuple[str, List]) -> Tuple[str, str]:
|
|
||||||
key, (void, void, category_key) = entry
|
key, (void, void, category_key) = entry
|
||||||
if category_key:
|
if category_key:
|
||||||
# using specified category key to sort
|
# using specified category key to sort
|
||||||
@ -108,11 +107,16 @@ class IndexEntries:
|
|||||||
lckey = unicodedata.normalize('NFD', key.lower())
|
lckey = unicodedata.normalize('NFD', key.lower())
|
||||||
if lckey.startswith('\N{RIGHT-TO-LEFT MARK}'):
|
if lckey.startswith('\N{RIGHT-TO-LEFT MARK}'):
|
||||||
lckey = lckey[1:]
|
lckey = lckey[1:]
|
||||||
|
|
||||||
if lckey[0:1].isalpha() or lckey.startswith('_'):
|
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
|
# ensure a determinstic order *within* letters by also sorting on
|
||||||
# the entry itself
|
# the entry itself
|
||||||
return (lckey, entry[0])
|
return (sortkey, entry[0])
|
||||||
newlist = sorted(new.items(), key=keyfunc)
|
newlist = sorted(new.items(), key=keyfunc)
|
||||||
|
|
||||||
if group_entries:
|
if group_entries:
|
||||||
|
@ -25,12 +25,14 @@ def test_create_single_index(app):
|
|||||||
".. index:: ёлка\n"
|
".. index:: ёлка\n"
|
||||||
".. index:: תירבע\n"
|
".. index:: תירבע\n"
|
||||||
".. index:: 9-symbol\n"
|
".. index:: 9-symbol\n"
|
||||||
".. index:: &-symbol\n")
|
".. index:: &-symbol\n"
|
||||||
|
".. index:: £100\n")
|
||||||
restructuredtext.parse(app, text)
|
restructuredtext.parse(app, text)
|
||||||
index = IndexEntries(app.env).create_index(app.builder)
|
index = IndexEntries(app.env).create_index(app.builder)
|
||||||
assert len(index) == 6
|
assert len(index) == 6
|
||||||
assert index[0] == ('Symbols', [('&-symbol', [[('', '#index-9')], [], None]),
|
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[1] == ('D', [('docutils', [[('', '#index-0')], [], None])])
|
||||||
assert index[2] == ('P', [('pip', [[], [('install', [('', '#index-2')]),
|
assert index[2] == ('P', [('pip', [[], [('install', [('', '#index-2')]),
|
||||||
('upgrade', [('', '#index-3')])], None]),
|
('upgrade', [('', '#index-3')])], None]),
|
||||||
|
Loading…
Reference in New Issue
Block a user