如何在文本中使用重组文本(RST2HTML.PY)或如何使用空白行插入HTML标签?

StackOverflow https://stackoverflow.com/questions/4669689

如何将颜色与重组文本一起使用?例如, **hello** 翻译成 <strong>hello</strong>. 。如何进行重组(rst2html.py)翻译 某物 进入 <font color="####">text</font>?

我想到.. raw :: html,但它引入了空白。我想插入没有空白行的HTML标签。

有帮助吗?

解决方案

我发现这种方法起作用

首先,您有角色。

.. role:: red

An example of using :red:`interpreted text`

它转化为如下。

<p>An example of using <span class="red">interpreted text</span></p>

现在,您拥有红色类,可以使用CSS来更改颜色。

.red {
    color:red;
}

其他提示

好吧,我现在是一个新用户,因此,由于Stackoverflow的策略,我无法对其他用户发表评论。 https://meta.stackexchange.com/questions/51926/new-users-cant-cant-ask-for-clarifications-except-as-answers

Sienkiew的答案很好,但我想对其最后一句话进行更正。

有方法可以在第一个文件中指定样式表。线索是在ProsSeek的原始帖子中,即.. RAW :: Directive。

我们可以在第一个文件的开头将以下行放置以指定其样式。

.. raw:: html

    <style> .red {color:red} </style>

这里的另一个答案暗示了我想做的事情,但是它假设了有关模仿者中样式表的一些详细知识。这是AA食谱说明:

在您的第一个文件中,声明角色一次,然后使用它:

    .. role:: red

    This text is :red:`colored red` and so is :red:`this`

然后,您需要一个样式表文件。首先,使用Python从Docutils软件包中复制默认样式表:

    python
    import os.path
    import shutil
    import docutils.writers.html4css1 as h
    shutil.copy(os.path.dirname(h.__file__)+"/html4css1.css","my.css")

然后编辑my.css在最后添加您的自定义:

    .red {
            color: red;
    }

创建一个名为“ docutils.conf”的Docutils配置文件:

    [html4css1 writer]
    stylesheet-path: my.css
    embed-stylesheet: yes

使用rst2html.py转换您的文档:

    rst2html.py my_document.rst > my_document.html

如果您不想使用docutils.conf,则每次运行RST2HTML时都可以指定样式表:

    rst2html.py --stylesheet my.css my_document.rst > my_document.html

afaik,无法在第一个文件中指定样式表。

将 @prosseek's和 @rayluo的答案全部结合在一起 - 使得更易于找到

在第一个文件的顶部,放置

.. raw:: html

    <style> .red {color:red} </style>

.. role:: red

:red:`test - this text should be red`

旁注:

当然,正如@sienkiew所说,许多人会希望在单独的文件中使用该样式。

但不总是。

例如,我正在从我希望其他用户能够运行的脚本中生成上述内容,通常是从文件URL运行的。根据rst2html.py的不同 - 需要在配置文件中进行非标准的东西更糟。

如果有一种方法可以为样式创建弱的本地定义,例如“如果没有样式。但是AFAIK本地定义更强。

这与 rst2html.py (Docutils 0.13.1 [release], Python 3.6.4, on cygwin), ,但其他第一个工具被拒绝。

这样为我工作:

.. raw:: html

    <style> .red {color:#aa0060; font-weight:bold; font-size:16px} </style>

.. role:: red

:red:`test - this text should be red``
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top