【问题标题】:Deindent Block in Sphinx literalinclude DirectiveSphinx 文字中的 Deindent 块包含指令
【发布时间】:2021-12-27 16:40:46
【问题描述】:

我在一个文件中有一段代码,我想将其包含在 Sphinx 文档的示例中,使用 literalinclude 指令。

但是该代码在一个函数中,所以当我包含它时,在示例中,每一行的缩进比我想要的多一级。

.. literalinclude:: ../../examples/example.py
   :language: python
   :lines: 13-42
   :tab-width: 0

生产

    import foo
    from foo import bar

    print("I'm indented too far")

还有其他方法可以删除或取消缩进文字块吗?

【问题讨论】:

    标签: python-sphinx restructuredtext


    【解决方案1】:

    literalinclude 有一个dedent 选项:

    .. literalinclude:: ../../examples/example.py
       :language: python
       :lines: 13-42
       :tab-width: 0
       :dedent: 4
    

    literalinclude 文档的“其他选项”下提到了该选项,但详细信息在 the documentation for code-block 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-06
      • 1970-01-01
      相关资源
      最近更新 更多