Sphinx 中的 HTML 变量 [英] HTML variables in Sphinx

查看:35
本文介绍了Sphinx 中的 HTML 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 conf.py 中插入一个应用于字符串的链接的变量:

I'm trying to have a variable in conf.py that inserts a link that is applied on a string:

rst_epilog = """
.. |support| replace:: `support team <support@blabla.com>`_
"""

在这种情况下,支持团队"会变成指向电子邮件地址的链接.

In this case 'support team' would turn into a link pointing to the email address.

不幸的是,这不起作用并且构建中断.

Unfortunately, this does not work and the build breaks.

所以我尝试在那里转储 HTML,不知道替换何时发生,但它发生在 HTML 转换之前,所以这在我的输出中不起作用.

So I've tried dumping HTML in there, not knowing when the substitution happens, but it happens before HTML conversion, so that does not work in my output.

rst_epilog = """
.. |support| replace:: <a href="support@blabla.com">support team</a>
"""

知道我可以用变量来做到这一点吗?

Any idea I could do this with a variable?

推荐答案

使用这个替换定义:

.. |support| replace:: support team support@blabla.com

support@blabla.com 被自动识别为 mailto 链接.

support@blabla.com is automatically recognized as a mailto link.

|support| 替换引用产生以下输出:

The |support| substitution reference produces the following output:

support team <a class="reference external" href="mailto:support&#37;&#52;&#48;blabla&#46;com">support<span>&#64;</span>blabla<span>&#46;</span>com</a>

<小时>

另一种方法是使用 raw-html 角色(参见 http://docutils.sourceforge.net/docs/ref/rst/roles.html#raw).

将此添加到 conf.py:

Add this to conf.py:

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

.. |support| replace:: :raw-html:`<a href="mailto:support@blabla.com">support team</a>`
"""

这篇关于Sphinx 中的 HTML 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆