summaryrefslogtreecommitdiff
path: root/sphinx/ext/apidoc.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-05-02 22:40:36 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-05-04 17:19:31 +0900
commite41d6f3651416ca6ce31d637b572895264661f00 (patch)
treea75f09ff6d4613cf7e039b356bddf4d9b19bbe9f /sphinx/ext/apidoc.py
parentb482e38ca2e81b241b3c16f72d5df9296a267389 (diff)
downloadsphinx-git-e41d6f3651416ca6ce31d637b572895264661f00.tar.gz
apidoc: Use a template for generating toc file
Diffstat (limited to 'sphinx/ext/apidoc.py')
-rw-r--r--sphinx/ext/apidoc.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/sphinx/ext/apidoc.py b/sphinx/ext/apidoc.py
index 00c5fe8cc..8c8101307 100644
--- a/sphinx/ext/apidoc.py
+++ b/sphinx/ext/apidoc.py
@@ -174,19 +174,21 @@ def create_package_file(root, master_package, subroot, py_files, opts, subs, is_
def create_modules_toc_file(modules, opts, name='modules'):
# type: (List[str], Any, str) -> None
"""Create the module's index."""
- text = format_heading(1, '%s' % opts.header, escape=False)
- text += '.. toctree::\n'
- text += ' :maxdepth: %s\n\n' % opts.maxdepth
-
modules.sort()
prev_module = ''
- for module in modules:
+ for module in modules[:]:
# look if the module is a subpackage and, if yes, ignore it
if module.startswith(prev_module + '.'):
- continue
- prev_module = module
- text += ' %s\n' % module
+ modules.remove(module)
+ else:
+ prev_module = module
+ context = {
+ 'header': opts.header,
+ 'maxdepth': opts.maxdepth,
+ 'docnames': modules,
+ }
+ text = ReSTRenderer(template_dir).render('toc.rst', context)
write_file(name, text, opts)