首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >docutils/reStructuredText模板特性

docutils/reStructuredText模板特性
EN

Stack Overflow用户
提问于 2012-03-19 14:43:23
回答 2查看 2.9K关注 0票数 0

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

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

代码语言:javascript
复制
Header
------------------------------------ 
${custom_text}

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

代码语言:javascript
复制
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命令:

代码语言:javascript
复制
custom_text=this is the value of custom property

有可能吗?reStructuredText完全支持模板特性吗?

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-03-20 10:42:33

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

代码语言:javascript
复制
I am using |RST|.

.. |RST| replace:: reStructuredText

将导致文本

我在用reStructuredText。

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

example.rst

代码语言:javascript
复制
Header
======

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

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

properties.rst

代码语言:javascript
复制
.. |my custom text| replace:: "example text"

将产生以下文件:

标题

我可以包括文本,如“示例文本”,从其他文件。

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

票数 10
EN

Stack Overflow用户

发布于 2019-09-19 14:26:04

有几种处理模板的选项:

( a)使用内部替代机制:

template.txt::

代码语言:javascript
复制
 Header
 ======

 |custom text|

example.txt::

代码语言:javascript
复制
 .. |custom text| replace:: this is the value of custom property

使用rst2html example.txt -o example.html进行转换。

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

( b)编写自己的包装器:一个读取templateproperties文件的Python进行替换,并使用Docutils.core中的一个函数进行转换。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9772228

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档