Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 229
Timur Fayzrakhmanov Avatar asked Oct 23 '25 16:10

Timur Fayzrakhmanov


1 Answers

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.

like image 190
Steve Piercy Avatar answered Oct 26 '25 10:10

Steve Piercy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!