Python 如何使用Sphinx链接到str方法?
我使用Sphinx从文档字符串生成HTML文档,就像一个好的小蟒蛇 我有一个文档字符串,看起来像这样:Python 如何使用Sphinx链接到str方法?,python,python-sphinx,docstring,Python,Python Sphinx,Docstring,我使用Sphinx从文档字符串生成HTML文档,就像一个好的小蟒蛇 我有一个文档字符串,看起来像这样: def do_a_thing(text): ''' Call the ``str.strip()`` method on ``text``. Then do something else with it. ''' 然而,我希望它链接到,而不仅仅是所有的单空间和代码块 我尝试了几种方法: :py:func:`str.strip()` :mod:`str.stri
def do_a_thing(text):
'''
Call the ``str.strip()`` method on ``text``. Then do something
else with it.
'''
然而,我希望它链接到,而不仅仅是所有的单空间和代码块
我尝试了几种方法:
:py:func:`str.strip()`
:mod:`str.strip()`
:class:`str.strip()`
:any:`str.strip()`
:doc:`str.strip()`
这些方法都不管用——或者更准确地说,前四种方法给了我一个单间距的粗体字体,但它们实际上都没有链接到任何地方。并且any
指令向我发出警告:“未找到任何”参考目标:str.strip()
显然,我可以自己制作一个链接,但这看起来很恶心,而且可能不是我想要的,因为当我升级到Python4时会怎么样?然后我必须更新我文档中的所有链接,这太糟糕了
链接到str方法的Python文档的正确方式是什么?ftw
在conf.py
中,添加几行。金字塔文档提供了添加和的好例子
及
然后在.rst文件中,有几种方法可以指向Python文档。我们倾向于使用以下格式,向文档作者表明链接将解析为指定的外部文档源
:mod:`venv module <python:venv>`
:ref:`package <python:tut-packages>`
就版本控制而言,您可以在intersphinx映射中使用多个名称或更新目标映射
intersphinx_mapping = {
#...
'python2': ('https://docs.python.org/2', None),
'python': ('https://docs.python.org/3', None), # use "python" for default version
#...
}
或者在将来
intersphinx_mapping = {
#...
'python2': ('https://docs.python.org/2', None),
'python3': ('https://docs.python.org/3', None),
'python': ('https://docs.python.org/4', None), # use "python" for default version
#...
}
我已经把intersphinx配置成这样了。我尝试了
,它链接到https://docs.python.org/3/tutorial/modules.html#tut-软件包
。但是,如果我把
放在那里,比如https://docs.python.org/3/library/stdtypes.html#str.lstrip
它没有将我链接到那里。我更新了您特定项目的答案。对于Python,还可以使用中的任何指令,包括::py:meth:str.strip
:py:meth:`str.strip`
intersphinx_mapping = {
#...
'python2': ('https://docs.python.org/2', None),
'python': ('https://docs.python.org/3', None), # use "python" for default version
#...
}
intersphinx_mapping = {
#...
'python2': ('https://docs.python.org/2', None),
'python3': ('https://docs.python.org/3', None),
'python': ('https://docs.python.org/4', None), # use "python" for default version
#...
}