小智 6

only

only指令用于包含/排除基于的内容tags.tags可以指定:

  1. 在conf.py中(这个用法only很相似ifconfig)
  2. 使用-t标志sphinx-build(不作为标志,make因为-t--touch标志make)

    example.rst

    .. only:: draft
    
       This message only appears in drafts.
    
    Run Code Online (Sandbox Code Playgroud)

    命令

    $ sphinx-build  -t draft  -b html -d _build/doctrees . _build/html
    
    Run Code Online (Sandbox Code Playgroud)
  3. 构建器的格式或名称.这是only闪耀的地方... only:: html内容只有在您使用make html等时才能构建

    example.rst

    .. only:: html
    
       This message only appears in HTML output.
    
    Run Code Online (Sandbox Code Playgroud)

    命令

    $ make html
    
    Run Code Online (Sandbox Code Playgroud)

ifconfig

ifconfig使您能够灵活地根据涉及在conf.py中注册的配置变量的任何Python表达式的真实性来包含内容.但这意味着您必须编辑conf.py以更改是包含还是排除内容.

结论

如果你希望你的内容更改,恕不编辑您想要conf.py only.例如,我使用在我的HTML文档中only包含目录(contents指令),但不是在我的pdf文档中(因为LaTeX自己生成这些文档).