简体   繁体   English

Sphinx 文档中的条件输出

[英]Conditional output in Sphinx Documentation

I'm writing some documentation with Sphinx and I'd like to print out a certain block of text only for HTML documentation, not for LaTeX documentation.我正在用Sphinx编写一些文档,我想打印出仅用于 HTML 文档的特定文本块,而不是用于 LaTeX 文档。 Something tells me I should be able to do this with sphinx.ext.ifconfig but I can't figure out how.有人告诉我我应该可以用sphinx.ext.ifconfig做到这一点,但我不知道怎么做。 Does anyone know how to do this?有谁知道如何做到这一点?

No extension is required.不需要扩展。 Just use the only directive.只需使用only指令。

(old link, from original 2010 post) (旧链接,来自 2010 年原始帖子)
https://web.archive.org/web/20100129001557/http://sphinx.pocoo.org/markup/misc.html#including-content-based-on-tags https://web.archive.org/web/20100129001557/http://sphinx.pocoo.org/markup/misc.html#include-content-based-on-tags

(latest link) (最新链接)
https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#including-content-based-on-tags https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#include-content-based-on-tags

It works like this:它是这样工作的:

.. only:: latex

    The stuff in here only appears in the latex output.

.. only:: html

    The stuff in this block only appears in the HTML output. It's
    often useful to use this directive with it:

    .. raw:: html

        It's good for embedding stuff, like video.

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

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