Python 使用Sphinx格式化多行docstring
使用,是否有方法以特殊方式格式化多行docstring的第一行 考虑:Python 使用Sphinx格式化多行docstring,python,python-sphinx,autodoc,Python,Python Sphinx,Autodoc,使用,是否有方法以特殊方式格式化多行docstring的第一行 考虑: def whatever(): """This function does something. This really should have a full function definition, but I am too lazy. Some more stuff. """ 正在生成的html代码: <dd> <p>This function does som
def whatever():
"""This function does something.
This really should have a full function definition, but I am too lazy.
Some more stuff.
"""
正在生成的html代码:
<dd>
<p>This function does something.</p>
<p>This really should have a full function definition, but I am too lazy. Some more stuff.</p>
</dd>
这个函数做了一些事情
这真的应该有一个完整的函数定义,但我太懒了。再来点东西
我希望它是这样的:
<dd>
<p class='headline'>This function does something.</p>
<p>This really should have a full function definition, but I am too lazy. Some more stuff.</p>
</dd>
此函数起作用
这真的应该有一个完整的函数定义,但我太懒了。再来点东西
据我所知,autodoc没有为您提供很多标记文档字符串的功能,特别是在向文档字符串添加自定义样式方面。有两种方法可以解决这个问题:1)在**中包装第一行,这个函数做了一些事情**
,所以它将被加粗。2) 编写一个自定义sphinx扩展,在autodoc解析文档字符串之前拦截它们,并相应地处理它们
(我最终选择了选项2,以便在我的docstrings中包含节标题…下面是该扩展的示例。它不满足您的需要,但它可能是一个有用的起点,特别是
\u remove\u oneline
函数对模块docstrings所做的) 谢谢,这看起来是个合理的方法。