How do I force a line break/new line in rst? I don't want it to be a new paragraph (ie. no additional spaces between the lines), I just want the text to start on a new line. Thanks!
3 Answers
The line block syntax also worked, and was a bit cleaner:
| This is a line
| This is another line
| Another new line
-
1And this works with github rst (where raw html and many directives are not available).– coldfixMay 7, 2019 at 16:58
-
Works in
VS Code
onWindows 10
without anything else required (just add a|
to every line beginning of the subsequent lines you would like to have as a contiguous block having newlines without empty lines between them) Jun 10, 2021 at 12:49 -
1Maybe it's just
pypi.org
, however it did not give me a line break without a new paragraph. To get a new line immediately following a few long lines I have to a) start a new (empty) line and b) THEN (on the next line) follow it with| <my new line>
. This works ... <my new line> immediately comes after the previous text.– AendieAug 29, 2022 at 17:48 -
This should be the accepted solution, as it works for a much wider variety of use cases Mar 23 at 14:42
According to the docs for docutils raw
role, you can do this:
If there just *has* to be a line break here,
:raw-html:`<br />`
it can be accomplished with a "raw"-derived role.
But the line block syntax should be considered first.
You will need to define the raw
role first:
.. role:: raw-html(raw)
:format: html
As the example states, consider line block syntax first.
| Lend us a couple of bob till Thursday.
| I'm absolutely skint.
| But I'm expecting a postal order and I can pay you back
as soon as it comes.
| Love, Ewan.
-
Thanks. This required defining the raw role first:
.. role:: raw-html(raw) :format: html
– tiggeraeJul 6, 2018 at 19:01 -
1It might be worth noting that you must indent before each | for it to start a new line. Sep 4, 2019 at 13:58
-
2@asrjarratt not according to docutils. One may, not must, and only if nesting is desired. Sep 4, 2019 at 20:38
-
@StevePiercy I stand corrected. I think there was a case where I was having trouble getting it to work without indenting it, and I've just been indenting ever since. Thanks for pointing that out. Sep 5, 2019 at 12:50
We added a substitution to our global.rst
file so we didn't have to add raw tags all the time.
.. |br| raw:: html
<br/>
This way we can just use |br|
when we need a line break.
-
3To avoid top & bottom padding of a linebreak, replace
<br/>
with<div style="line-height: 0; padding: 0; margin: 0"></div>
Aug 28, 2020 at 19:16 -
This I like. Light and specific. The other general raw HTML role answer is good too, but this minimal markup is nice. When using restview I also find that the given answer with
<br/>
works best and does not add top and bottom padding with my CSS. Using the suggested<div>
, though, leads to separation because therestview
parser appears to trigger an end of paragraph when encountering the<div>
tag, leading to exactly the opposite of what's needed.– NeilGNov 14 at 6:40