Search code examples
python-sphinxrestructuredtext

reStructuredText newline character breaks code blocks


I am using reStructuredText and Sphinx in order to generate a set of docs. Every page must be PEP8 compliant and therefore has a max of 80 characters per line. This is a new requirement and is breaking several pages.

When we used to have:

.. code-block:: bash
    really really long line of code that I would want a new user to copy and paste into a terminal

We now have:

.. code-block:: bash
    really really long line of code that
    I would want a new user to copy and
    paste into a terminal

Which is a problem as every line is treated like a separate command when pasting into the terminal. Reading the docs I see I could do something like:

| really really long line of code that I 
  would want a new user to copy and paste
  into a terminal

to make my text fit on 1 line, but this does not keep the block styling or syntax highlighting I want. Does anyone know of a way to achieve what I am looking for? Thanks in advance for any and all feedback!


Solution

  • You should be able to use a backslash to indicate that the line continues. It escapes the newline character.

    .. code-block:: bash
    
       really really long line of code that \
       I would want a new user to copy and \
       paste into a terminal
    

    The command is interpreted as one long line when pasted into a terminal.

    See http://www.gnu.org/software/bash/manual/bashref.html#Escape-Character.