mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Make it possible to deactivate the module index.
This commit is contained in:
parent
931cd9190a
commit
4d30e0bd40
@ -167,6 +167,10 @@ that use Sphinx' HTMLWriter class.
|
||||
Additional templates that should be rendered to HTML pages, must be a
|
||||
dictionary that maps document names to template names.
|
||||
|
||||
.. confval:: html_use_modindex
|
||||
|
||||
If true, add a module index to the HTML documents. Default is ``True``.
|
||||
|
||||
.. confval:: html_copy_source
|
||||
|
||||
If true, the reST sources are included in the HTML build as
|
||||
@ -217,3 +221,7 @@ These options influence LaTeX output.
|
||||
.. confval:: latex_preamble
|
||||
|
||||
Additional LaTeX markup for the preamble.
|
||||
|
||||
.. confval:: latex_use_modindex
|
||||
|
||||
If true, add a module index to LaTeX documents. Default is ``True``.
|
||||
|
@ -315,6 +315,7 @@ class StandaloneHTMLBuilder(Builder):
|
||||
version = self.config.version,
|
||||
last_updated = self.last_updated,
|
||||
style = self.config.html_style,
|
||||
use_modindex = self.config.html_use_modindex,
|
||||
builder = self.name,
|
||||
parents = [],
|
||||
titles = {},
|
||||
@ -387,46 +388,47 @@ class StandaloneHTMLBuilder(Builder):
|
||||
|
||||
# the global module index
|
||||
|
||||
# the sorted list of all modules, for the global module index
|
||||
modules = sorted(((mn, (self.get_relative_uri('modindex', fn) +
|
||||
'#module-' + mn, sy, pl, dep))
|
||||
for (mn, (fn, sy, pl, dep)) in self.env.modules.iteritems()),
|
||||
key=lambda x: x[0].lower())
|
||||
# collect all platforms
|
||||
platforms = set()
|
||||
# sort out collapsable modules
|
||||
modindexentries = []
|
||||
pmn = ''
|
||||
cg = 0 # collapse group
|
||||
fl = '' # first letter
|
||||
for mn, (fn, sy, pl, dep) in modules:
|
||||
pl = pl and pl.split(', ') or []
|
||||
platforms.update(pl)
|
||||
if fl != mn[0].lower() and mn[0] != '_':
|
||||
modindexentries.append(['', False, 0, False,
|
||||
mn[0].upper(), '', [], False])
|
||||
tn = mn.split('.')[0]
|
||||
if tn != mn:
|
||||
# submodule
|
||||
if pmn == tn:
|
||||
# first submodule - make parent collapsable
|
||||
modindexentries[-1][1] = True
|
||||
elif not pmn.startswith(tn):
|
||||
# submodule without parent in list, add dummy entry
|
||||
if self.config.html_use_modindex:
|
||||
# the sorted list of all modules, for the global module index
|
||||
modules = sorted(((mn, (self.get_relative_uri('modindex', fn) +
|
||||
'#module-' + mn, sy, pl, dep))
|
||||
for (mn, (fn, sy, pl, dep)) in self.env.modules.iteritems()),
|
||||
key=lambda x: x[0].lower())
|
||||
# collect all platforms
|
||||
platforms = set()
|
||||
# sort out collapsable modules
|
||||
modindexentries = []
|
||||
pmn = ''
|
||||
cg = 0 # collapse group
|
||||
fl = '' # first letter
|
||||
for mn, (fn, sy, pl, dep) in modules:
|
||||
pl = pl and pl.split(', ') or []
|
||||
platforms.update(pl)
|
||||
if fl != mn[0].lower() and mn[0] != '_':
|
||||
modindexentries.append(['', False, 0, False,
|
||||
mn[0].upper(), '', [], False])
|
||||
tn = mn.split('.')[0]
|
||||
if tn != mn:
|
||||
# submodule
|
||||
if pmn == tn:
|
||||
# first submodule - make parent collapsable
|
||||
modindexentries[-1][1] = True
|
||||
elif not pmn.startswith(tn):
|
||||
# submodule without parent in list, add dummy entry
|
||||
cg += 1
|
||||
modindexentries.append([tn, True, cg, False, '', '', [], False])
|
||||
else:
|
||||
cg += 1
|
||||
modindexentries.append([tn, True, cg, False, '', '', [], False])
|
||||
else:
|
||||
cg += 1
|
||||
modindexentries.append([mn, False, cg, (tn != mn), fn, sy, pl, dep])
|
||||
pmn = mn
|
||||
fl = mn[0].lower()
|
||||
platforms = sorted(platforms)
|
||||
modindexentries.append([mn, False, cg, (tn != mn), fn, sy, pl, dep])
|
||||
pmn = mn
|
||||
fl = mn[0].lower()
|
||||
platforms = sorted(platforms)
|
||||
|
||||
modindexcontext = dict(
|
||||
modindexentries = modindexentries,
|
||||
platforms = platforms,
|
||||
)
|
||||
self.handle_page('modindex', modindexcontext, 'modindex.html')
|
||||
modindexcontext = dict(
|
||||
modindexentries = modindexentries,
|
||||
platforms = platforms,
|
||||
)
|
||||
self.handle_page('modindex', modindexcontext, 'modindex.html')
|
||||
|
||||
# the search page
|
||||
self.handle_page('search', {}, 'search.html')
|
||||
|
@ -53,6 +53,7 @@ class Config(object):
|
||||
html_index = ('', False),
|
||||
html_sidebars = ({}, False),
|
||||
html_additional_pages = ({}, False),
|
||||
html_use_modindex = (True, False),
|
||||
html_copy_source = (True, False),
|
||||
|
||||
# HTML help options
|
||||
@ -64,6 +65,7 @@ class Config(object):
|
||||
latex_documents = ([], False),
|
||||
latex_preamble = ('', False),
|
||||
latex_appendices = ([], False),
|
||||
latex_use_modindex = (True, False),
|
||||
)
|
||||
|
||||
def __init__(self, dirname, filename):
|
||||
|
@ -33,11 +33,9 @@ HEADER = r'''%% Generated by Sphinx.
|
||||
\author{%(author)s}
|
||||
%(preamble)s
|
||||
\makeindex
|
||||
\makemodindex
|
||||
'''
|
||||
|
||||
FOOTER = r'''
|
||||
\printmodindex
|
||||
\printindex
|
||||
\end{document}
|
||||
'''
|
||||
@ -57,15 +55,9 @@ class LaTeXWriter(writers.Writer):
|
||||
self.builder = builder
|
||||
|
||||
def translate(self):
|
||||
try:
|
||||
visitor = LaTeXTranslator(self.document, self.builder)
|
||||
self.document.walkabout(visitor)
|
||||
self.output = visitor.astext()
|
||||
except:
|
||||
import pdb, sys, traceback
|
||||
traceback.print_exc()
|
||||
tb = sys.exc_info()[2]
|
||||
pdb.post_mortem(tb)
|
||||
visitor = LaTeXTranslator(self.document, self.builder)
|
||||
self.document.walkabout(visitor)
|
||||
self.output = visitor.astext()
|
||||
|
||||
|
||||
# Helper classes
|
||||
@ -100,6 +92,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
'papersize': paper,
|
||||
'pointsize': builder.config.latex_font_size,
|
||||
'preamble': builder.config.latex_preamble,
|
||||
'modindex': builder.config.latex_use_modindex,
|
||||
'author': document.settings.author,
|
||||
'docname': document.settings.docname,
|
||||
# if empty, the title is set to the first section title
|
||||
@ -127,8 +120,10 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
|
||||
def astext(self):
|
||||
return (HEADER % self.options) + \
|
||||
(self.options['modindex'] and '\\makemodindex\n' or '') + \
|
||||
self.highlighter.get_stylesheet() + '\n\n' + \
|
||||
u''.join(self.body) + \
|
||||
(self.options['modindex'] and '\\printmodindex\n' or '') + \
|
||||
(FOOTER % self.options)
|
||||
|
||||
def visit_document(self, node):
|
||||
|
@ -117,6 +117,9 @@ html_last_updated_fmt = '%%b %%d, %%Y'
|
||||
# template names.
|
||||
#html_additional_pages = {}
|
||||
|
||||
# If false, no module index is generated.
|
||||
#html_use_modindex = True
|
||||
|
||||
# If true, the reST sources are included in the HTML build as _sources/<name>.
|
||||
#html_copy_source = True
|
||||
|
||||
@ -142,6 +145,9 @@ htmlhelp_basename = '%(project)sdoc'
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#latex_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#latex_use_modindex = True
|
||||
'''
|
||||
|
||||
MASTER_FILE = '''\
|
||||
|
@ -9,7 +9,9 @@
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px"><a href="{{ pathto('genindex') }}" title="General Index" accesskey="I">index</a></li>
|
||||
{%- if use_modindex %}
|
||||
<li class="right"><a href="{{ pathto('modindex') }}" title="Global Module Index" accesskey="M">modules</a> |</li>
|
||||
{%- endif %}
|
||||
{%- if next %}
|
||||
<li class="right"><a href="{{ next.link|e }}" title="{{ next.title|striptags }}" accesskey="N">next</a> |</li>
|
||||
{%- endif %}
|
||||
|
Loading…
Reference in New Issue
Block a user