URL中的Sphinx替换

时间:2016-08-25 16:50:43

标签: python-sphinx restructuredtext

我有两个项目A和B,项目A的文档正在托管不同版本,因此文档网址的格式为

http://example.org/A/1.0.0/+d/index.html
http://example.org/A/1.0.1/+d/index.html
http://example.org/A/1.2.3/+d/index.html

项目B取决于特定版本的A.在B的文档中,我想留下A这样的文档的链接:

“另见A's documentation(v 1.0.1)”

是否可以将版本变量传递给URL?我尝试使用rst_prolog

conf.py

rst_prolog = '''
.. |a-ver| replace:: {ver}
'''.format(
    ver=meta.__a_dep_version__,
)

index.rst

A's version: |a-ver| # this produces the correct output
See also `framework docs <http://example.com/A/|a-ver|/index.html>`_.

但在构建doc之后获取URL https://example.com/A/%7Ca-ver%7C/+d/index.html

1 个答案:

答案 0 :(得分:1)

您可以使用sphinx.ext.extlinks扩展程序。

实施例

Sphinx配置

extlinks = {'docs': ('http://example.org/A/%s/+d/index.html', 'framework docs ')}

您的文档

:docs:`1.0.1`
.. Result -> framework docs 1.0.1

:docs:`documentation (1.2.3) <1.2.3>`
.. Result -> documentation (1.2.3)