summaryrefslogtreecommitdiff
path: root/sphinx/util
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2011-01-07 19:00:29 +0100
committerGeorg Brandl <georg@python.org>2011-01-07 19:00:29 +0100
commit554c7dd64f6aca38be6e1d26bb2cf4388f46083d (patch)
treea2318b0357a85ab129c5be18df18ce0db2759312 /sphinx/util
parent3448ad3099e0c30e6901589b6bd8e181a449c6aa (diff)
downloadsphinx-554c7dd64f6aca38be6e1d26bb2cf4388f46083d.tar.gz
#454: Add more index markup capabilities: marking see/seealso entries, and main entries for a given key.
Diffstat (limited to 'sphinx/util')
-rw-r--r--sphinx/util/__init__.py8
-rw-r--r--sphinx/util/nodes.py19
2 files changed, 22 insertions, 5 deletions
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py
index d51f0208..becaff0b 100644
--- a/sphinx/util/__init__.py
+++ b/sphinx/util/__init__.py
@@ -285,6 +285,14 @@ def rpartition(s, t):
return '', s
+def split_into(n, type, value):
+ """Split an index entry into a given number of parts at semicolons."""
+ parts = map(lambda x: x.strip(), value.split(';', n-1))
+ if sum(1 for part in parts if part) < n:
+ raise ValueError('invalid %s index entry %r' % (type, value))
+ return parts
+
+
def format_exception_cut_frames(x=1):
"""Format an exception with traceback, but only the last x frames."""
typ, val, tb = sys.exc_info()
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py
index 09ab8b88..a241f574 100644
--- a/sphinx/util/nodes.py
+++ b/sphinx/util/nodes.py
@@ -74,17 +74,22 @@ def split_explicit_title(text):
indextypes = [
- 'single', 'pair', 'double', 'triple',
+ 'single', 'pair', 'double', 'triple', 'see', 'seealso',
]
def process_index_entry(entry, targetid):
indexentries = []
entry = entry.strip()
+ oentry = entry
+ main = ''
+ if entry.startswith('!'):
+ main = 'main'
+ entry = entry[1:].lstrip()
for type in pairindextypes:
if entry.startswith(type+':'):
value = entry[len(type)+1:].strip()
value = pairindextypes[type] + '; ' + value
- indexentries.append(('pair', value, targetid, value))
+ indexentries.append(('pair', value, targetid, main))
break
else:
for type in indextypes:
@@ -92,15 +97,19 @@ def process_index_entry(entry, targetid):
value = entry[len(type)+1:].strip()
if type == 'double':
type = 'pair'
- indexentries.append((type, value, targetid, value))
+ indexentries.append((type, value, targetid, main))
break
# shorthand notation for single entries
else:
- for value in entry.split(','):
+ for value in oentry.split(','):
value = value.strip()
+ main = ''
+ if value.startswith('!'):
+ main = 'main'
+ value = value[1:].lstrip()
if not value:
continue
- indexentries.append(('single', value, targetid, value))
+ indexentries.append(('single', value, targetid, main))
return indexentries