Documentation 文档/重构文本模板功能
如何使用实际值自定义Documentation 文档/重构文本模板功能,documentation,markup,restructuredtext,docutils,Documentation,Markup,Restructuredtext,Docutils,如何使用实际值自定义.rst文件中的占位符 例如,我有example.rst文件,其中包含以下内容: Header ------------------------------------ ${custom_text} custom_text=this is the value of custom property 我想用值替换${custom_text}属性这是自定义属性的值,方法是运行以下命令: rst2html example.rst -o example.html -Dcustom
.rst
文件中的占位符
例如,我有example.rst
文件,其中包含以下内容:
Header
------------------------------------
${custom_text}
custom_text=this is the value of custom property
我想用值替换${custom_text}
属性这是自定义属性的值,方法是运行以下命令:
rst2html example.rst -o example.html -Dcustom_text="this is the value of custom property"
我还想知道是否可以使用.properties
文件自定义模板?例如,我想使用包含以下内容的example.properties
文件运行rst2html example.rst-o example.html-p example.properties
命令:
Header
------------------------------------
${custom_text}
custom_text=this is the value of custom property
可能吗?StructuredText是否完全支持模板功能
编辑:请注意,我想从命令行或使用传统的.properties
文件自定义模板(可由Ant/Maven构建管理工具使用)。使用指令执行StructuredText文件中的替换。例如:
I am using |RST|.
.. |RST| replace:: reStructuredText
将生成文本
我正在使用重构文本
可以使用该指令在单独的文件中定义替换模板列表。例如,给定以下两个文件:
示例.rst:
属性.rst
将产生以下文件:
标题
我可以包含来自其他文件的文本,如“示例文本”
这里我使用命令rst2html.py example.rst来生成HTML输出。有几个选项可以处理模板化:
a) 使用内部替代机制:
template.txt::
Header
======
|custom text|
example.txt::
.. |custom text| replace:: this is the value of custom property
使用rst2html example.txt-o example.html
进行转换
通过这种方式,您可以处理内联文本和图像
b) 编写您自己的包装器:一个Python脚本,它读取模板
和属性
文件,进行替换,并使用Docutils.core中的一个函数进行转换。您对StructuredText的模板功能给出了很好的回答。我需要承认,我不知道StructuredText的模板功能,尽管我认为应该有某种方法。但是,我担心这并不能解决我的问题——我想从命令行或使用传统的.properties
文件(可由Ant/Maven构建管理工具使用)自定义模板,您必须自己编写这些东西。由于rst2html.py没有-p
或-D
选项,因此需要某种包装脚本。-D
行为可以通过运行重构的文本文件(例如,C语言预处理器)来实现。当我有更多的时间时,我会考虑一下属性文件。但是,您希望以一种非设计使用的方式使用StructuredText,这可能比它的价值更麻烦。好的,我明白了。看来你是对的-我应该使用另一种格式。有没有办法使用replace指令进行多行替换?我不能让它这样做。