Timur Fayzrakhmanov
Timur Fayzrakhmanov

Reputation: 19587

How to create RST codeblock without preceding spaces?

What I really love in Markdown is that I can do the following:

  1. Write ```Enter
  2. Paste any trash I have in my clipboard
  3. Write ```
  4. I now have a working code block

In RST I have to do the following:

  1. Write .. codeblock::EnterEnter
  2. Paste
  3. Now I need to indent all the lines I previously pasted

Does RST has any simpler way to use codeblock without the need of preceding four spaces?

Upvotes: 3

Views: 1506

Answers (1)

Steve Piercy
Steve Piercy

Reputation: 15055

There is nothing similar in reST to markdown's inline code block. There are only 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.

If your editor lacks the ability to automatically indent code-block, or does not allow you to select the block and indent four spaces, then the best option may be literalinclude. It's especially useful if you refer to the same code repeatedly.

p.s. -- Try indenting four spaces after the second return. I tried in PyCharm, but it didn't indent, but maybe your editor will do it. There are several open issues for PyCharm.

Upvotes: 1

Related Questions