簡體   English   中英

從Sphinx文檔中刪除“module”一詞

[英]Remove the word “module” from Sphinx documentation

使用Sphinx記錄我的Python項目。 我想刪除每個python文件名稱后面的“模塊”一詞 (在導航欄,TOC,頁面標題等)。

詳情:

該項目由兩個文件utils.pymain.py

在我的index.rst文件中,我使用:

.. toctree::
   :maxdepth: 2

   utils
   main

將這兩個文件導入為“模塊”。 docs/文件夾中,我然后調用:

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

生成靜態站點。 在網站中,“模塊”一詞跟在每個文件名后面,我想將其刪除。

一個可能的解決方案使用JS在頁面加載查找並替換單詞“module”:

使用以下內容創建文件source/_templates/layout.html

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

確保conf.py設置了templates_path = ['_templates'] ,然后Sphinx會將腳本附加到所有文檔頁面的<head> ,瞧!

Sphinx 2.2為sphinx-apidoc生成的reST文件添加了模板。

使用--templatedir選項設置包含module.rst_tpackage.rst_ttoc.rst_t文件的目錄的路徑。 可以從site-packages/sphinx/templates/apidoc的相應文件創建文件。

然后,在package.rst_t替換

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

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

module.rst_t重復module.rst_t

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM