好的,这就是我的做法。首先,apilinks.py
(Sphinx 扩展):
from docutils import nodes, utils
def setup(app):
def api_link_role(role, rawtext, text, lineno, inliner, options={},
content=[]):
ref = app.config.apilinks_base + text
node = nodes.reference(rawtext, utils.unescape(ref), refuri=ref,
**options)
return [node], []
app.add_config_value('apilinks_base', 'http://localhost/', False)
app.add_role('apilink', api_link_role)
现在,在 中conf.py
,添加到扩展列表并为(否则,它将默认为)'apilinks'
设置适当的值。我的文件如下所示:'apilinks_base'
'http://localhost/'
extensions = ['sphinx.ext.autodoc', 'apilinks']
# lots of other stuff
apilinks_base = 'http://host:88/base/'
用法:
:apilink:`path`
输出:
<a href="http://host:88/base/path">http://host:88/base/path</a>