14

Using Sphinx for documenting my Python project. I want to remove the word "module" which follows the name of each python file (in the navbar, TOC, the page title, etc).

e.g. Details:

The project is composed of 2 files utils.py and main.py.

In my index.rst file, I use:

.. toctree:: :maxdepth: 2 utils main 

to import both files as "modules". From the docs/ folder, I then call:

sphinx-apidoc -f -o ./source/ .. make html 

to generate the static site. In the site, the word "module" follows every file name, and I would like to remove it.

2
  • After sphinx-apidoc -f -o ./source/ .., what is in your utils.rst and main.rst? I think part of the problem is that sphinx-apidoc is designed for packages, not modules: "sphinx-apidoc is a tool for automatic generation of Sphinx sources that, using the autodoc extension, document a whole package in the style of other automatic API documentation tools." Commented May 16, 2018 at 4:09
  • 1
    Possible duplicate of stackoverflow.com/q/29385564/407651 Commented May 16, 2018 at 4:41

2 Answers 2

16

Sphinx 2.2 adds templating for the reST files generated by sphinx-apidoc.

Use the --templatedir option to set the path to a dir containing module.rst_t, package.rst_t and toc.rst_t files. The files can be created from the corresponding files in site-packages/sphinx/templates/apidoc.

Then, in package.rst_treplace

{{- [submodule, "module"] | join(" ") | e | heading(2) }} 

with

{{- submodule | e | heading(2) }} 

Repeat for module.rst_t.

Sign up to request clarification or add additional context in comments.

6 Comments

According to sphinx-doc.org/en/master/changes.html#id9, the --templatedir option was added already in Sphinx 2.2.0.
@mzjn True, but as far as I could tell, that version wasn't released (not available via PyPI / pip).
Strange that it does not work for you. I was able to install it via pip. And pypi.org/project/Sphinx says that 2.2.0 is the latest release.
Ah -- it was released on Aug 18. I posted this answer on the 16th :)
I can't find the default files in site-packages/sphinx/templates/apidoc on my computer, but you can find them here
|
2

One possible solution uses JS to find & replace the word "module" after the page loads:

Create a file source/_templates/layout.html with the following content:

{% extends "!layout.html" %} {% block extrahead %} <script type="text/javascript"> window.onload = function() { document.body.innerHTML = document.body.innerHTML.replace(/ module/g, ''); } </script> {% endblock %} 

Make sure that conf.py has templates_path = ['_templates'] set, then Sphinx will append the script to the <head> of all documentation pages, and voila!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.