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.
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_t
replace
{{- [submodule, "module"] | join(" ") | e | heading(2) }}
with
{{- submodule | e | heading(2) }}
Repeat for module.rst_t
.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With