【问题标题】:Sphinx substitution in URLURL 中的 Sphinx 替换
【发布时间】:2016-08-25 16:50:42
【问题描述】:

我有两个项目 A 和 B,项目 A 的文档针对不同的版本托管,因此文档 url 的格式为

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>`_.

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

【问题讨论】:

    标签: python-sphinx substitution restructuredtext


    【解决方案1】:

    您可以为此使用sphinx.ext.extlinks 扩展名。

    示例

    狮身人面像配置

    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)
    

    【讨论】:

      猜你喜欢
      • 2012-02-07
      • 2020-09-28
      • 2010-11-16
      • 1970-01-01
      • 1970-01-01
      • 2014-06-11
      • 1970-01-01
      • 1970-01-01
      • 2013-12-29
      相关资源
      最近更新 更多