瓦里亚布狮身人面像

2024-04-27 15:21:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Sphinx为新项目编写文档

但是因为这个项目是新的,它的名字可能会改变,我不想在我的所有文档中替换“项目名”的所有引用。

所以我想知道是否有办法在Sphinx上设置一些变量/常量。

我知道在Sphinx上有一个i18n特性,所以我可以使用gettext来更改“项目名”,而不需要其他东西。但我在找一个合适的方法。


Tags: 项目方法文档sphinx特性名字i18ngettext
2条回答

项目名由sphinx使用配置值引用。系统会询问您是否使用sphinx-quickstart创建xyoursphinx项目的名称。 您可以通过更改conf.py中的project来更改项目名称

您可以在.rst文件中使用配置值,方法是在conf.py中用rst_epilog定义它们(请参见this answer示例)。

Sphinx documentation

reST supports “substitutions” (ref), which are pieces of text and/or markup referred to in the text by |name|. They are defined like footnotes with explicit markup blocks, like this:

.. |name| replace:: replacement *text*

or this:

.. |caution| image:: warning.png
         :alt: Warning!

See the reST reference for substitutions for details.

If you want to use some substitutions for all documents, put them into rst_prolog or rst_epilog or put them into a separate file and include it into all documents you want to use them in, using the include directive. (Be sure to give the include file a file name extension differing from that of other source files, to avoid Sphinx finding it as a standalone document.)

rst_prolog中添加“项目变量”并使用替换。

相关问题 更多 >