[英]Inline Code Link in Sphinx + reStructuredText
In Markdown, one can create an inline code link like so在 Markdown 中,可以像这样创建内联代码链接
[`dict.update`](https://docs.python.org/3/library/stdtypes.html#dict.update)
Which renders like dict.update
.呈现像
dict.update
。 How can get a similar behaviour in reStructuredText / Sphinx?如何在 reStructuredText / Sphinx 中获得类似的行为? I tried (1) using a converter but it never results in something similar (2) nesting external link
`link <link>`_
and inline code block :code:`dict.update`
, but that din't work either.我尝试 (1) 使用转换器,但它永远不会产生类似的结果 (2) 嵌套外部链接
`link <link>`_
和内联代码块:code:`dict.update`
,但这也不起作用。
The right way to do this is using the sphinx.ext.intersphinx
extension.正确的方法是使用
sphinx.ext.intersphinx
扩展。
In your conf.py
add在你的
conf.py
添加
extensions = [
'sphinx.ext.intersphinx', # the last entry does not use a comma.
# 'sphinx.ext.autodoc', # just for example so there is more than 1 line.
]
intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}
# If you having an `objects.inv` for local builds
# intersphinx_mapping = {"python": ("https://docs.python.org/3", 'objects.inv'),}
Then in your .rst
file or in the docstrings in the .py
files write a simple cross-reference.然后在您的
.rst
文件或.py
文件的文档字符串中编写一个简单的交叉引用。 Notice that dict.update
is a method thus the right role ( :py:meth:
) should be used when cross-referencing.请注意,
dict.update
是一种方法,因此在交叉引用时应使用正确的角色( :py:meth:
)。 The following example下面的例子
A simple text to :meth:`dict.update`
Would give the below HTML output (the tooltip and link of the cross-reference also included in the screenshot)将给出以下 HTML output (交叉引用的工具提示和链接也包含在屏幕截图中)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.