在 reStructuredText 中使用 <i> 标签

Using <i> tags in reStructuredText

我知道以下语法适用于 <em> 标签:

:emphasis:`lorum ipsum`
*lorum ipsum*

如何生成 <i> 标签?我似乎无法在 Markup Specification.

中找到任何提及

强调由单个星号字符括起来的文本:

这是强调的文本。 强调的文本通常以斜体显示。

在我们深入探讨之前,您确定您真的需要 <i> 标签吗?人们经常使用 <i> 而实际上他们的意思是 <em>...默认情况下它们几乎总是一样的...

没有?您真的需要 <i> 个标签>?好的,那我们开始吧。


为了控制 docutils 发出的 HTML 标签,您需要创建一个新的 "writer"。这些是生成任何所需格式输出的 docutils 组件(例如 HTML、LateX 等)。

您可以在 docutils 源代码库 here.

中找到 docutils 附带的各种 HTML 作者

这需要编写一些 Python 代码。基本上 up 需要提供一个 Python class 来发出你想要的 HTML。

简要查看源代码,您可能可以子 class 最适合您需要的 HTML 作者(现在您可能想要 html5_polyglot)并覆盖 visit_emphasis 方法。

然后您需要找到一种方法来告诉 docutils 使用 您的新编写器。查看 tools directory 中的一些示例。

如果您使用的是 Sphinx,我真的不确定如何让其他作者加入其中。您可能需要修改(或 monkeypatch)Sphinx 源代码。

自 Docutils 版本 0.17(rsp。存储库版本 0.17dev)以来,“html5”编写器将写入标签,如果匹配 class 值 在 inlineliteral 元素中找到::

.. role:: i

In the "html5" writer output,
:i:`this text is set in a <i> Element`.

This works also with other roles, 
if you give them the "i" class value, e.g.:

.. role:: alternative-voice
   :class: i, language-la

Lemonade consists primarily of :alternative-voice:`Citrus limon`.

将示例复制到文件“foo.txt”,比如 并调用 rst2html5.py foo.txt foo.html 查看结果。