如何自定义狮身人面像中的python域?

发布于 2025-01-17 14:30:21 字数 286 浏览 2 评论 0原文

我想自定义 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过去的过去 2025-01-24 14:30:21

是的,确实如此,但它需要代码(自定义扩展)并且可能并不容易。

可能有一种更简单的方法,但是通过子类化 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 of doc_field_types and registering this with app.add_directive_to_domain("py", "class", YourClass, override=True) in a setup(app) fonction in your conf.py, you might get what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文