【问题标题】:Standardizing a link using a global variable in Sphinx documentation在 Sphinx 文档中使用全局变量标准化链接
【发布时间】:2019-08-08 17:22:04
【问题描述】:

我正在使用 Sphinx 来记录一个工作项目。我想在我的文档中使用指向多个页面上的下载的相同链接。

例如: home.rst:

Hi
==

I want you to download_ my project.

.. _download: blah.com/download

other_page.rst

Hello Again
===========
You can also download_ it here.

.. _download: blah.com/download

有没有办法让每个页面都指向一个变量,这样当链接需要更新时,只需要更新变量?

【问题讨论】:

标签: python-sphinx restructuredtext


【解决方案1】:

最好的选择是使用substitutionrst_epilograw-html,如answer for mailto links 中所述。

在你的conf.py

rst_epilog = """
.. role:: raw-html(raw)
   :format: html

.. |download| replace:: :raw-html:`<a href="https://blah.com/download/">download</a>`
"""

在你的*.rst:

Please |download| my file.

extlink extension 很接近,但假设您希望使用 URL 作为其他站点链接的基础。

【讨论】:

  • 你也可以把.. _download: blah.com/download放到rst_epilog中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-26
  • 2023-01-03
  • 2011-05-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多