summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-01-10 22:19:40 +0100
committerGeorg Brandl <georg@python.org>2009-01-10 22:19:40 +0100
commit11a7ed8c495cd416df2c6b4bd10ce71630ac0efc (patch)
tree2bbf413e6013d669a45d5eafd8b323e7b2811e22
parentaedbdd953d4ea4129273294316c23780cda9cb3b (diff)
parentab4c11f641c907572765de4fbb1a829cc114e491 (diff)
downloadsphinx-git-11a7ed8c495cd416df2c6b4bd10ce71630ac0efc.tar.gz
merge with mq
-rw-r--r--CHANGES3
-rw-r--r--doc/conf.py3
-rw-r--r--doc/config.rst10
-rw-r--r--sphinx/builders/html.py40
-rw-r--r--sphinx/config.py1
-rw-r--r--sphinx/quickstart.py3
-rw-r--r--sphinx/themes/basic/modindex.html4
7 files changed, 55 insertions, 9 deletions
diff --git a/CHANGES b/CHANGES
index 47cfa672b..6e7d59343 100644
--- a/CHANGES
+++ b/CHANGES
@@ -61,6 +61,9 @@ New features added
- The default value for ``htmlhelp_basename`` is now the project
title, cleaned up as a filename.
+ - The new ``modindex_common_prefix`` config value can be used to
+ ignore certain package names for module index sorting.
+
* Builders:
- New builder for Qt help collections, by Antonio Valentino.
diff --git a/doc/conf.py b/doc/conf.py
index e1c89eaee..e1a48aa20 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -33,6 +33,9 @@ show_authors = True
# The HTML template theme.
html_theme = 'sphinxdoc'
+# A list of ignored prefixes names for module index sorting.
+modindex_common_prefix = ['sphinx.']
+
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
diff --git a/doc/config.rst b/doc/config.rst
index ff2ca9093..ad14d1ed8 100644
--- a/doc/config.rst
+++ b/doc/config.rst
@@ -164,6 +164,16 @@ General configuration
.. versionadded:: 0.5
+.. confval:: modindex_common_prefix
+
+ A list of prefixes that are ignored for sorting the module index (e.g.,
+ if this is set to ``['foo.']``, then ``foo.bar`` is shown under ``B``, not
+ ``F``). This can be handy if you document a project that consists of a single
+ package. Works only for the HTML builder currently. Default is ``[]``.
+
+ .. versionadded:: 0.6
+
+
Project information
-------------------
diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py
index 6d9a2ba87..52854559a 100644
--- a/sphinx/builders/html.py
+++ b/sphinx/builders/html.py
@@ -317,11 +317,24 @@ class StandaloneHTMLBuilder(Builder):
for mn, (fn, sy, pl, dep) in modules:
pl = pl and pl.split(', ') or []
platforms.update(pl)
+
+ ignore = self.env.config['modindex_common_prefix']
+ ignore = sorted(ignore, key=len, reverse=True)
+ for i in ignore:
+ if mn.startswith(i):
+ mn = mn[len(i):]
+ stripped = i
+ break
+ else:
+ stripped = ''
+
if fl != mn[0].lower() and mn[0] != '_':
# heading
- modindexentries.append(['', False, 0, False,
- mn[0].upper(), '', [], False])
- letters.append(mn[0].upper())
+ letter = mn[0].upper()
+ if letter not in letters:
+ modindexentries.append(['', False, 0, False,
+ letter, '', [], False, ''])
+ letters.append(letter)
tn = mn.split('.')[0]
if tn != mn:
# submodule
@@ -332,13 +345,13 @@ class StandaloneHTMLBuilder(Builder):
elif not pmn.startswith(tn):
# submodule without parent in list, add dummy entry
cg += 1
- modindexentries.append([tn, True, cg,
- False, '', '', [], False])
+ modindexentries.append([tn, True, cg, False, '', '',
+ [], False, stripped])
else:
num_toplevels += 1
cg += 1
- modindexentries.append([mn, False, cg, (tn != mn),
- fn, sy, pl, dep])
+ modindexentries.append([mn, False, cg, (tn != mn), fn, sy, pl,
+ dep, stripped])
pmn = mn
fl = mn[0].lower()
platforms = sorted(platforms)
@@ -348,6 +361,19 @@ class StandaloneHTMLBuilder(Builder):
# number of submodules
collapse = len(modules) - num_toplevels < num_toplevels
+ # As some parts of the module names may have been stripped, those
+ # names have changed, thus it is necessary to sort the entries.
+ if ignore:
+ def sorthelper(entry):
+ name = entry[0]
+ if name == '':
+ # heading
+ name = entry[4]
+ return name.lower()
+
+ modindexentries.sort(key=sorthelper)
+ letters.sort()
+
modindexcontext = dict(
modindexentries = modindexentries,
platforms = platforms,
diff --git a/sphinx/config.py b/sphinx/config.py
index 5c3b7dfe6..0159e76e3 100644
--- a/sphinx/config.py
+++ b/sphinx/config.py
@@ -51,6 +51,7 @@ class Config(object):
templates_path = ([], False),
template_bridge = (None, False),
keep_warnings = (False, True),
+ modindex_common_prefix = ([], False),
# HTML options
html_theme = ('default', False),
diff --git a/sphinx/quickstart.py b/sphinx/quickstart.py
index c0a219efa..73def0dcf 100644
--- a/sphinx/quickstart.py
+++ b/sphinx/quickstart.py
@@ -108,6 +108,9 @@ exclude_trees = [%(exclude_trees)s]
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
# -- Options for HTML output ---------------------------------------------------
diff --git a/sphinx/themes/basic/modindex.html b/sphinx/themes/basic/modindex.html
index 6e33e55c2..0392edc80 100644
--- a/sphinx/themes/basic/modindex.html
+++ b/sphinx/themes/basic/modindex.html
@@ -18,7 +18,7 @@
<hr/>
<table width="100%" class="indextable" cellspacing="0" cellpadding="2">
- {%- for modname, collapse, cgroup, indent, fname, synops, pform, dep in modindexentries %}
+ {%- for modname, collapse, cgroup, indent, fname, synops, pform, dep, stripped in modindexentries %}
{%- if not modname -%}
<tr class="pcap"><td></td><td>&nbsp;</td><td></td></tr>
<tr class="cap"><td></td><td><a name="cap-{{ fname }}"><strong>{{ fname }}</strong></a></td><td></td></tr>
@@ -30,7 +30,7 @@
{%- endif %}</td>
<td>{% if indent %}&nbsp;&nbsp;&nbsp;{% endif %}
{% if fname %}<a href="{{ fname }}">{% endif -%}
- <tt class="xref">{{ modname|e }}</tt>
+ <tt class="xref">{{ stripped|e }}{{ modname|e }}</tt>
{%- if fname %}</a>{% endif %}
{%- if pform and pform[0] %} <em>({{ pform|join(', ') }})</em>{% endif -%}
</td><td>{% if dep %}<strong>{{ _('Deprecated')}}:</strong>{% endif %}