17

I have Sphinx text in the following format in source code:

Line 1 Line 2 Line 3 Line 4

I would like Line 4 to be rendered in HTML on a separate physical line. Is this possible?

mzjn
  • 48,958
  • 13
  • 128
  • 248
Jonathan
  • 2,635
  • 3
  • 30
  • 49

6 Answers6

29

Use line blocks:

| Line 1
| Line 2
| Line 3
| Line 4

Will produce:

Line 1
Line 2
Line 3
Line 4

banderlog013
  • 2,207
  • 24
  • 33
3

You can define a hard line break as follows:

.. # define a hard line break for HTML
.. |br| raw:: html

   <br />

You should define such aliases in a prolog.inc and reference it in you Sphinx configuration file.

Here is a usage example:

My first line |br|
My second line
Paebbels
  • 15,573
  • 13
  • 70
  • 139
  • 2
    This is a bad answer, since this hack will break when generating any document format but HTML. @banderlog013's reply has the proper solution. – Andreas Rossberg Apr 07 '21 at 09:26
2

I had to use directive line block, nothing else worked for me.

.. line-block::
   Line 1
   Line 2
Eda Jede
  • 81
  • 6
1

The solutions user14678546 and Paebbels also work for tables:

Using line blocks in tables is inconstant, not pretty, as well as it leaves a blank/additional line break at the end, resulting in ex. 3 lines but only the first 2 lines have text.

Here is an example of a line break in a table of reStructuredText (only for html):

.. table:: Truth table for "not"
  :width: 20%
  :widths: 1 3 1

  =====  =====    =====
  A      not A    Note
  =====  =====    =====
  False  True     Text here
  True   False    Comment here
         False
  False  True     Text here |br| line break in table here
  True   False
  =====  =====    =====

.. |br| raw:: html

     <br>

Using |br| inline in text in a table, results in a line brake in a single cell of text (in html): Table with line break

It also works for csv tables.

MERose
  • 4,048
  • 7
  • 53
  • 79
Skynet
  • 11
  • 3
  • 1
    "This work-around also works for table's!" What workaround are you referring to? – mzjn Apr 20 '21 at 10:07
  • Of using |br| inline in text in a table, resulting in a line brake in a single cell of text (in html). That might not have been clear enough. – Skynet Apr 20 '21 at 10:34
  • Yes, avoid unclear references such as "This work-around...". An answer should stand on its own. Stack Overflow is not a traditional discussion forum. – mzjn Apr 20 '21 at 10:46
  • Yes. I'm new to this (which I guess you have figured out) and I really wanted to quote or referee to "user14678546" or "Paebbels" answer, but didn't find that option. Or should I have putt it as a comment of "user14678546" or "Paebbels" answer? But then I guess that I didn't have the option of giving an example formatted as code? Or should I even have created a new question and then answer my own question? – Skynet Apr 20 '21 at 10:57
  • It is not forbidden to mention other answers. Just make sure it is clear which answer you are referring to. – mzjn Apr 20 '21 at 11:02
0

You can use:

Line 1 |br|
Line 2 |br|
Line 3 |br|
Line 4 |br|

At the end of the file you need to put:

.. |br| raw:: html

      <br>

Note: This does not work when making latex code.

0

In the source code, just add extra empty line and it will do the job. for example:

    Line 1
    
    Line 2
    
    Line 3