我想将以下链接引用到我的其中一个reST文档中:https://docs.python.org/3/library/stdtypes.html#typecontextmanager。我试图使用:ref:
内联指令而不是链接。我跑python -m sphinx.ext.intersphinx https://docs.python.org/3/objects.inv
。结果表明,除其他事项外:如何通过sphinx链接到Python 3中的typecontextmanager标签通过sphinx
... std:label 23acks Acknowledgements : whatsnew/2.3.html#acks 23section-other Other Changes and Fixes : whatsnew/2.3.html#section-other ... typebytearray Bytearray Objects : library/stdtypes.html#typebytearray typebytes Bytes Objects : library/stdtypes.html#typebytes typecontextmanager Context Manager Types : library/stdtypes.html#typecontextmanager typeiter Iterator Types : library/stdtypes.html#typeiter typememoryview Memory Views : library/stdtypes.html#typememoryview ...
加粗的URL正是我期待的,因为我的intersphinx_mapping
看起来是这样的:
intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
}
我用下面的指令:
:ref:`context manager <python:typecontextmanager>`
这似乎是指向正确的标签,但我得到以下警告:
WARNING: undefined label: python:typecontextmanager (if the link has no caption the label must precede a section header)
:ref:
被替换为字符串context manager
,但没有链接。
我缺少什么?
我使用的狮身人面像1.6.3上的蟒蛇安装Python 3.6.2的
注1
我使用:ref:`with <python:with>`
同样的问题,这是应该指向https://docs.python.org/3/reference/compound_stmts.html#with,根据库存线(也下std:label
):
with The with statement : reference/compound_stmts.html#with
我猜测到的主要问题的解决方案将最有可能解决这一点。
注2
可能不是100%的相关性,但我可以在相同的部分链接到:py:meth:`~contextmanager.__enter__`
没有任何问题。
我没有看到我们的参考之间有任何根本的区别在这里。我会做一个“干净”,看看是否有帮助。 –
'干净'固定它。但是,您的答案中有一些有价值的提示,因此我会选择它以保持代表流畅。 –
在我对另一个问题的回答中有几个其他选项:https://stackoverflow.com/a/43908388/2214933。 Sphinx将解析后的reST文件缓存为“doctree pickles”,而不是Python源代码文件,然后写入输出。它只查找新的和已更改的文件。所以如果你没有改变你的reST文件并在上一次运行后保存它,那么输出中的变化将永远不会显示。我有时只是添加一个换行符并保存它以强制当前文件运行。 –