python - 在 Sphinx 中使用自定义 HTML 编写器

标签 python python-sphinx

如何在 sphinx.writers.html 中使用与 Sphinx 附带的不同的 HTMLTranslator

具体来说,我想修改方法depart_desc_signature。我无法修改 Sphinx 本身,因为帮助文件是与其他人一起开发的,需要使用标准 Sphinx 正确编译。

我知道Sphinx支持:

最佳答案

所选答案在最新版本的 Sphinx 中不再有效。我在 sphinx-users 邮件列表上询问,并且 Jean Abou Samra 非常友善地给了我以下解释和可以放入 conf.py 的示例代码:

配置文件中的setup()函数获取应用程序 对象并可以改变它。例如,conf.py 中的这段代码将 将所有强调标记解释为粗体:

from sphinx.writers.html import HTMLTranslator

class MyTranslator(HTMLTranslator):
     def visit_emphasis(self, node):
         self.visit_strong(node)
     def depart_emphasis(self, node):
         self.depart_strong(node)

def setup(app):
     app.set_translator('html', MyTranslator)

关于python - 在 Sphinx 中使用自定义 HTML 编写器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15555088/

相关文章:

python - 如何让IPython Notebook不显示上一次 session 的结果?

python-sphinx - 在 Sphinx RTD 站点上每个页面的顶部添加警告指令

Python 文档字符串 : What do these docstring parameters mean exactly?

python - 如何让 Sphinx 理解 Sage doctests?

python - Patentsview API Python 3.4

python - 在 python 中绘制流数据的最轻量级方法

python - OS X 中的屏幕录制进程比 Python 的多处理更快?

python - Scikit-learn:避免高斯过程回归中的过度拟合

python - 如何在自定义 python-sphinx 指令/扩展中使用现有指令?

inline - 如何通过在 python-sphinx 中使用角色来使用唯一的内联指令?