我想將以下鏈接引用到我的其中一個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文件並在上一次運行後保存它,那麼輸出中的變化將永遠不會顯示。我有時只是添加一個換行符並保存它以強制當前文件運行。 –