如何创建没有前置空格的 RST 代码块?

How to create RST codeblock without preceding spaces?

我真正喜欢 Markdown 的地方在于我可以做到以下几点:

  1. 写入```输入
  2. 粘贴我剪贴板中的所有垃圾
  3. ```
  4. 我现在有一个工作代码块

在 RST 中,我必须执行以下操作:

  1. 写入.. codeblock::输入输入
  2. 粘贴
  3. 现在我需要缩进我之前粘贴的所有行

RST 是否有任何更简单的方法来使用代码块而不需要前面的四个空格?

reST 与 markdown 的内联代码块没有任何相似之处。只有these options:

There are multiple ways to show syntax-highlighted literal code blocks in Sphinx: using reST doctest blocks; using reST literal blocks, optionally in combination with the highlight directive; using the code-block directive; and using the literalinclude directive.

如果您的编辑器没有自动缩进 code-block 的功能,或者不允许您 select 块和缩进四个空格,那么最好的选择可能是 literalinclude。如果您重复引用相同的代码,它会特别有用。

p.s。 -- 尝试在第二个 return 后缩进四个空格。我在 PyCharm 中试过,但它没有缩进,但也许你的编辑器会这样做。有several open issues for PyCharm.