0

如何.rst使用实际值自定义文件中的占位符?

例如,我有example.rst以下内容的文件:

Header
------------------------------------ 
${custom_text}

我想通过运行以下命令将${custom_text}属性替换为值:this is the value of custom property

rst2html example.rst -o example.html -Dcustom_text="this is the value of custom property"

另外我想知道是否可以使用.properties文件自定义模板?例如,我想使用具有以下内容的文件运行rst2html example.rst -o example.html -p example.properties命令:example.properties

custom_text=this is the value of custom property

可能吗?reStructuredText 是否完全支持模板功能?

编辑:请注意,我想从命令行自定义模板或使用常规.properties文件(可由 Ant/Maven 构建管理工具使用)。

4

2 回答 2

10

使用指令执行 reStructuredText 文件中的替换replace。例如:

I am using |RST|.

.. |RST| replace:: reStructuredText

将导致文本

我正在使用 reStructuredText。

您可以使用该include指令在单独的文件中定义替换模板列表。例如,给定以下两个文件:

示例.rst

Header
======

.. Include templates from external file (this is a comment).
.. include:: properties.rst

I can include text, like |my custom text|, from other files.

属性.rst

.. |my custom text| replace:: "example text"

将导致文件:

标题

我可以包含来自其他文件的文本,例如“示例文本”。

在这里,我使用了该命令rst2html.py example.rst来生成 HTML 输出。

于 2012-03-20T10:42:33.770 回答
0

有几种处理模板的选项:

a) 使用内部替换机制:

模板.txt::

 Header
 ======

 |custom text|

示例.txt::

 .. |custom text| replace:: this is the value of custom property

转换为rst2html example.txt -o example.html.

这样您就可以处理内联文本和图像。

b) 编写您自己的包装器:一个 Python 脚本,用于读取templateproperties 归档、执行替换并使用 Docutils.core 中的一个函数进行转换。

于 2019-09-19T14:26:04.223 回答