Reputation: 1369
I have some generated reStructuredText that has code blocks with long lines. Is there a way to enforce line breaks just like normal lines (not in blocks) are wrapped?
Here's an example where rst2pdf reduces the font size of the block to make the whole line fit on the pdf page:
.. code-block::
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
Upvotes: 1
Views: 183
Reputation: 897
A literal block may be given a class value:
.. class:: wrapped-literal
::
\This *is a literal-block with class value_.
It is **not** parsed for \rST\ syntax.
This becomes even simpler for a code block:
.. code:: python
:class: wrapped-code
s_ = "This is a code block with class value."
In HTML, the CSS feature "whitespace: pre-wrap" would allow wrapping. In LaTeX, you would need some re-definitions in the preamble. I don't know how to achieve styling in the 3rd-party "rst2pdf" (reportlab) tool.
Alternatively, you may use the code role (that wraps by default):
Emulating a code block:
:code:`This is a long line of code that may wrap in the output.`
:code:`Next line of code in this block.`
The problem with this approach is leading whitespace.
Upvotes: 0
Reputation: 1986
I don't think rst2pdf has a way to break those lines - because it's a code block, it won't adjust anything. You could try applying a different (non-literal) style instead, and setting that up to do what you wanted.
Upvotes: 1