如何自定义狮身人面像中的python域?
我想自定义 Sphinx Python 域以识别方法文档字符串中的自定义字段并为其生成自定义 HTML。
例如,假设我想为模块中的每个方法添加一个类别。我希望能够编写这样的文档字符串:
def func():
“””
Does something
:category: A/B/C
“””
…
然后在生成的自动文档上显示自定义 HTML。
这可能吗?
I’d like to customize the Sphinx Python domain to recognize a custom field within a docstring for a method and generate custom HTML for it.
For example, let’s say I want to add a category for each method in a module. I want to be able to write a doc string like this:
def func():
“””
Does something
:category: A/B/C
“””
…
and then have custom HTML display on the generated autodoc.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,确实如此,但它需要代码(自定义扩展)并且可能并不容易。
可能有一种更简单的方法,但是通过子类化
PyClassLike
,可能会更改doc_field_types< 的值/code>
并将其注册为
app.add_directive_to_domain("py" , "class", YourClass, override=True)
在setup(app )
功能在您的conf.py
,你可能会得到你想要的。Yes, it is, but it will require code (a custom extension) and might not be easy.
There might be a simpler way, but by subclassing
PyClassLike
, probably changing the values ofdoc_field_types
and registering this withapp.add_directive_to_domain("py", "class", YourClass, override=True)
in asetup(app)
fonction in yourconf.py
, you might get what you want.