1

My restructuredText input file to Sphinx has a long line:

This is a long line text that I want to keep as a long single line. It should not be wrapped in the text output.

Using the text builder of Sphinx, I get this output:

This is a long line text that I want to keep as a long single line. It
should not be wrapped in the text output.

Sphinx wraps the line. I would like to keep the single long line as is. Is this possible?


Using Line Blocks was suggested in this answer. However using line blocks changes the indentation of the line. I could not find a way to keep the indentation same with Line Blocks.

For input:

Prev Line

| This is a long line text that I want to keep as a long single line. It should not be wrapped in the text output.

Next Line

I get this output:

Prev Line

   This is a long line text that I want to keep as a long single line. It should not be wrapped in the text output.

Next Line

The long line is kept long but it is indented now.


I was not able to find a setting about line wrapping in Sphinx configuration page.


I am using sphinx-build version 1.7.4 and the command I use is:

 sphinx-build -M text "." "_build"

Update:

The code-block directive also indents the long line.

Input:

Prev Line

.. code-block:: text

  This is a long line text that I want to keep as a long single line. It should not be wrapped in the text output.

Next Line

Output:

Prev Line

   This is a long line text that I want to keep as a long single line. It should not be wrapped in the text output.

Next Line
Hakan Baba
  • 1,897
  • 4
  • 21
  • 37
  • Perhaps `.. code-block:: text` preceding the long line, with the long line indented? I'm unsure how it will render in text output, but it works well for HTML output. – Steve Piercy May 10 '18 at 09:41
  • @StevePiercy Tried the `code-block` directive. It still indents the long line in the text output. Updated my question with an example. FYI. – Hakan Baba May 16 '18 at 15:55
  • That's not quite correct. The white-space you see is a result of CSS, not actual indentation with space characters. You can use a custom CSS file to override your theme that removes left- and right-padding from the `
    ` tag. See a related answer here: https://stackoverflow.com/a/45501239/2214933
    – Steve Piercy May 16 '18 at 22:00
  • @StevePiercy I am using the [text builder](http://www.sphinx-doc.org/en/master/builders.html#sphinx.builders.text.TextBuilder) of Sphinx. The output is not html but a raw text file. In that case, are the css files used ? – Hakan Baba May 17 '18 at 00:19
  • Ah, my mistake, I missed that you were using the text builder. I don't know if there is a way to do what you want. I'd suggest asking through Sphinx's support channels. – Steve Piercy May 17 '18 at 06:01

1 Answers1

0

Monkey-patching the rendering of line blocks for Text writer works for me:

add this to conf.py

def my_visit_line_block(self, node):
    # type: (nodes.Node) -> None
    self.new_state(indent=0)
    self.lineblocklevel += 1

def setup(app):
    from sphinx.writers.text import TextTranslator
    TextTranslator.visit_line_block = my_visit_line_block

The obvious defect is that it modifies rendering of all line blocks...

I am not familiar enough about sphinx.writers.text (and docutils) to see immediately if there is better way than the above monkey-patching.

I could re-insert indentation via this mark-up:

| \    one
| \    two
| \    three

but being forced to modify mark-up is bad.