在 (Python) Sphinx 文档中*按原样*包含文本文件

发布于 2024-09-03 01:13:20 字数 648 浏览 1 评论 0原文

(使用 Python-Sphinx 文档工具)

我有一个 .txt 日志文件,我想将其构建到 _build/html 未更改中。我需要在 conf.pyindex.rst 等中更改什么。

这是布局:

src/
    index.rst
    some_doc.rst
    somefile.txt

How do I get somefile.txt进入 html 构建?我尝试添加这样的行 to index.rst

Contents:

.. toctree::
   :maxdepth: 2

   some_doc
   "somefile.txt"

希望它能神奇地工作,但这里没有魔法!

假设这是可能的,我会在 some_doc.rst 中放入什么来引用/链接 到那个文件?

注意是的,我知道我可以将它放在/static中,然后就可以完成它, 但这看起来完全是一种黑客行为,而且很丑陋。

(using Python-Sphinx Documentation tool)

I have a .txt log file I'd like to build into _build/html unaltered. What do I need to alter in conf.py, index.rst, etc.

Here is the layout:

src/
    index.rst
    some_doc.rst
    somefile.txt

How do I get somefile.txt into the html build? I tried adding a line like this
to index.rst:

Contents:

.. toctree::
   :maxdepth: 2

   some_doc
   "somefile.txt"

hoping it would work by magic, but no magic here!

Assuming this is even possible, what would I put in some_doc.rst to refer/link
to that file?

Note Yes, I'm aware I could put it in /static and just be done with it,
but that seems like a total hack, and ugly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怼怹恏 2024-09-10 01:13:27

您可以在 sphinx 中使用以下内容

.. literalinclude:: file.txt
   :text:

它将显示文件的内容,就像它在代码块中一样。

You can use the following in sphinx

.. literalinclude:: file.txt
   :text:

It will show the content of the file, as if it were in a code block.

桃酥萝莉 2024-09-10 01:13:26

我认为您可以包含外部文档片段,如下所述:

http://docutils.sourceforge.net/docs/ref/rst/directives.html#include-an-external-document-fragment

从该文本中,应该执行以下操作:

.. include:: inclusion.txt
   :literal:

I think you can include an external document fragment, as described here:

http://docutils.sourceforge.net/docs/ref/rst/directives.html#including-an-external-document-fragment

From that text, something like this should do it:

.. include:: inclusion.txt
   :literal:
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文