How do I create a new line with reStructuredText?

2020-08-09 06:19发布

问题:

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!

回答1:

The line block syntax also worked, and was a bit cleaner:

| This is a line | This is another line | Another new line



回答2:

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.


回答3:

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.