我正在使用Sphinx从我的docstrings中生成我的HTML文档,比如一个好的'Pythonista'。如何链接到使用Sphinx的str方法?
我有一个文档字符串看起来像这样:
def do_a_thing(text):
'''
Call the ``str.strip()`` method on ``text``. Then do something
else with it.
'''
不过,我希望它链接到https://docs.python.org/3/library/stdtypes.html#str.strip,而不是仅仅将所有的等宽字体和代码块状。
我试过几个途径:这些工作
:py:func:`str.strip()`
:mod:`str.strip()`
:class:`str.strip()`
:any:`str.strip()`
:doc:`str.strip()`
无 - 或者更准确地说,前四个办法给我等宽&加粗字体,但它们都没有实际联系的任何地方。而any
指令给我WARNING: 'any' reference target not found: str.strip()
显然我可以自己建立一个链接,但这看起来很严重,也可能并不完全是我想要的,因为当我升级到Python 4时呢?然后,我必须更新我的文档中的所有链接,这很糟糕。
链接到str方法的Python文档的正确方法是什么?
所以,我已经有了配置,像这样的intersphinx。我尝试了'',并且它链接到了'https:// docs.python.org/3/docs/ modules.html#tut-packages'。但是,如果我把''放在那里,就像'https:// docs.python.org/3/library/stdtypes.html# str.lstrip'末尾的内容那样链接我在那里。 –
我更新了你的具体项目的答案。对于Python,您还可以使用[Python域名](http://www.sphinx-doc.org/en/stable/domains.html#the-python-domain)中的任何指令,其中包括: : py:meth:'str.strip' –
':py:meth:'正是我需要的 - 谢谢! –