在 (Python) Sphinx 文档中*按原样*包含文本文件
(使用 Python-Sphinx 文档工具)
我有一个 .txt
日志文件,我想将其构建到 _build/html
未更改中。我需要在 conf.py
、index.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正确答案是
:download :
角色。参见: Georg 的回答在 Sphinx 邮件列表中
The correct answer is the
:download:
role.Cf: Georg's answer on the Sphinx Mailing List
您可以在 sphinx 中使用以下内容
它将显示文件的内容,就像它在代码块中一样。
You can use the following in sphinx
It will show the content of the file, as if it were in a code block.
我认为您可以包含外部文档片段,如下所述:
http://docutils.sourceforge.net/docs/ref/rst/directives.html#include-an-external-document-fragment
从该文本中,应该执行以下操作:
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: