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ディレクティブを使用して、別のファイルに置換テンプレートのリストを定義できます。たとえば、次の2つのファイルがあるとします。

example.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.

propertys.rst

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

ドキュメントになります:

ヘッダ

「サンプルテキスト」のようなテキストを他のファイルから含めることができます。

ここでは、コマンドを使用しrst2html.py example.rstてHTML出力を生成しました。

于 2012-03-20T10:42:33.770 に答える
0

テンプレートを処理するためのいくつかのオプションがあります。

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)独自のラッパーを作成します。読み取りtemplateproperties ファイル化を行い、置換を実行し、Docutils.coreの関数の1つで変換するPythonスクリプトです。

于 2019-09-19T14:26:04.223 に答える