Skip to content Skip to sidebar Skip to footer

Sphinx Extension: Literal Block With Leading And/or Trailing Blank Lines?

As far as I can tell, it is not possible to create a literal text block (e.g. with the code-block directive) that starts or ends with a blank line, because this would be ambiguous

Solution 1:

I would rather try with CSS margin-top and margin-bottom properties.


Solution 2:

I found an answer to my own question, but it is far more complicated then I hoped ...

I created a custom node class and added a literal_block instance as a child node. I'm saving the number of empty lines as attributes of the custom node class. Then I created "visit" and "depart" functions (actually only the latter) for HTML and LaTeX that take the numbers from the node attributes and do some un-elegant string replacement on self.body fumbling the newlines into place.

This works fine for both HTML and LaTeX but I'd be happy to hear about a more elegant solution!


Post a Comment for "Sphinx Extension: Literal Block With Leading And/or Trailing Blank Lines?"