Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
sphinx.util.index_entries
(#11528)
- Loading branch information
Showing
10 changed files
with
76 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from __future__ import annotations | ||
|
||
|
||
def split_index_msg(entry_type: str, value: str) -> list[str]: | ||
# new entry types must be listed in util/nodes.py! | ||
if entry_type == 'single': | ||
try: | ||
return _split_into(2, 'single', value) | ||
except ValueError: | ||
return _split_into(1, 'single', value) | ||
if entry_type == 'pair': | ||
return _split_into(2, 'pair', value) | ||
if entry_type == 'triple': | ||
return _split_into(3, 'triple', value) | ||
if entry_type in {'see', 'seealso'}: | ||
return _split_into(2, 'see', value) | ||
raise ValueError(f'invalid {entry_type} index entry {value!r}') | ||
|
||
|
||
def _split_into(n: int, type: str, value: str) -> list[str]: | ||
"""Split an index entry into a given number of parts at semicolons.""" | ||
parts = [x.strip() for x in value.split(';', n - 1)] | ||
if len(list(filter(None, parts))) < n: | ||
raise ValueError(f'invalid {type} index entry {value!r}') | ||
return parts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters