在sphinx中使用自定义html编写器(use custom html writer in sphinx)

编程入门 行业动态 更新时间:2024-10-28 00:19:04
在sphinx中使用自定义html编写器(use custom html writer in sphinx)

如何在sphinx.writers.html使用与Sphinx sphinx.writers.html ?

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

我知道Sphinx支持:

扩展模块: http : //sphinx-doc.org/ext/appapi.html 自定义构建器: http : //sphinx-doc.org/ext/builderapi.html

How can I use a different HTMLTranslator than the one that ships with Sphinx in sphinx.writers.html?

Specifically, I want to modify the method depart_desc_signature. I can't modify Sphinx itself because the help files are being developed with others and need to compile correctly with standard Sphinx.

I know Sphinx supports:

extension modules: http://sphinx-doc.org/ext/appapi.html custom builders: http://sphinx-doc.org/ext/builderapi.html

最满意答案

通过在conf.py定义html_translator_class来指定html转换conf.py 。

例如,

html_translator_class = 'html2.HTMLTranslator'

这对mathjax来说效果不好,所以如果html2是html2的副本,你需要显式地将对mathjax的调用添加到HTMLTranslator:

def visit_displaymath(self, node): import sphinx.ext.mathjax sphinx.ext.mathjax.html_visit_displaymath(self, node) def depart_displaymath(self, node): return def visit_math(self, node): import sphinx.ext.mathjax sphinx.ext.mathjax.html_visit_math(self, node) def depart_math(self, node): return

Specify an html translator by defining an html_translator_class in conf.py.

For example,

html_translator_class = 'html2.HTMLTranslator'

This does not play nice with mathjax though, so if html2 is otherwise a copy of sphinx.writers.html, you need to explicitly add calls to mathjax to HTMLTranslator:

def visit_displaymath(self, node): import sphinx.ext.mathjax sphinx.ext.mathjax.html_visit_displaymath(self, node) def depart_displaymath(self, node): return def visit_math(self, node): import sphinx.ext.mathjax sphinx.ext.mathjax.html_visit_math(self, node) def depart_math(self, node): return

更多推荐

本文发布于:2023-07-28 23:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1310104.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   sphinx   html   writer   custom

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!