简体   繁体   English

Sphinx 和 reStructuredText:在 include 指令中传递参数

[英]Sphinx and reStructuredText: pass parameter in include directive

I am a newbie in Sphinx and reStructuredText.我是 Sphinx 和 reStructuredText 的新手。

I have n rst files in which I would like to insert a similar text ( not code ):我有 n rst 文件,我想在其中插入类似的文本(不是代码):

Hello Earth.

or或者

Hello Mars.

or或者

Hello Saturn.

My idea is to include in my rst files a common rst file.我的想法是在我的 rst 文件中包含一个通用的 rst 文件。

.. include:: planet.rst

with planet.rst and a placeholder for the planet in this file:在此文件中使用 planet.rst 和行星的占位符:

Hello <planet>.

My current solution is: planet.rst:我目前的解决方案是:planet.rst:

Hello Earth.
Hello Mars.
Hello Saturn.

and in my n rst files, eg for planet Mars:在我的第 n 个文件中,例如火星:

.. include:: planet.rst
   :start-line: 1
   :end-line: 2

I am looking for a better solution.我正在寻找更好的解决方案。

I didn't found a purposeful option for the include directive in http://docutils.sourceforge.net/docs/ref/rst/directives.html我没有在http://docutils.sourceforge.net/docs/ref/rst/directives.html中找到包含指令的有目的的选项

How can I pass a parameter (variable/value) to the included file to replace placeholder?如何将参数(变量/值)传递给包含的文件以替换占位符?

Thank's for your hints Thomas谢谢你的提示托马斯

The directive for "Replacement Text ( replace )" should work with included files. “替换文本( replace )”的指令应该适用于包含的文件。

planet.rst : planet.rst

Hello |planet|.

earth.rst : earth.rst

.. |planet| replace:: Earth

.. include:: planet.rst

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM