Inconsistent line spacing in RestructuredText docu

2019-07-13 09:04发布

问题:

I'm build RST files for my company's documentation. One irritating thing is that enumerated lists don't seem to have any consistency in terms of line spacing.

Is there a simple way to solve this?

Robert

回答1:

It's a well known problem of docutils, the library on which Sphinx is built.

From Sphinx issue tracker on GitHub:

tk0miya wrote:
In my short investigation:

The behavior comes from docutils (base library of Sphinx). In docutils.writers.html4css1.HTMLTranslator, docutils generates <p> tag if list includes any items excepting paragraphs and nested lists.

To fix this, set self.compact_simple in visit_list_item instead of visit_bullet_list and visit_enumerated_list. But we have to know why docutils check whole of list.

Source: Spinx-Doc/Sphinx #2258 - Nested field lists inside list items cause unwanted space in HTML output


See related issues:

  • https://github.com/rtfd/sphinx_rtd_theme/issues/119


回答2:

I'm unsure how to apply Paebbels answer, however I was able to get rid of the <p> tags by changing to the html4 writer by adding this line to my conf.py.

html4_writer = true

This obviously changes it to the html4 writer, so you'll need to determine whether this is acceptable or not.