Menu

#349 p tag not included if there is only one paragraph in container (html)

closed-wont-fix
nobody
None
5
2020-03-03
2018-08-11
No

When docutils generates an HTML file, the DOM is not the same if there is only one paragraph or several one in a container.
For example:

one paragraph

paragraphe

paragraphe

The demo shows it can be a problem visualy if the p tag has specific CSS. The CSS will be applyied in the second case but not in the first case.

You can check the demo by extracting the attached archive, cd demo and run:
$ rst2html.py --stylesheet style.css demo.rst demo.html

It work properly with rst2html5.

I read the source code and I found the visit_container() function however I failed to find where it's called.

1 Attachments

Discussion

  • Günter Milde

    Günter Milde - 2018-11-21
    • status: open --> closed-wont-fix
     
  • Günter Milde

    Günter Milde - 2018-11-21

    The behaviour is limited to the "legacy" HTML writer html4css1. It is documented as intended in the docstring of docutils.writers.html4css1.HTMLTranslator:

    The html4css1 writer has been optimized to produce visually compact
    lists (less vertical whitespace).
    ...
    It would be best to stick with strict body elements in list items, but they
    affect vertical spacing in older browsers (although they really shouldn't).
    ...
    In non-list contexts, omit

    tags on a paragraph if that
    paragraph is the only child of its parent (footnotes & citations
    are allowed a label first).

    The simple workaround would be to use the html5 writer or adapt your CSS definitions.

    If you need XHTML 4.1 for some reason, the function to look at would be
    should_be_compact_paragraph() in docutils/writers/html4css1/init.py which is called by
    visit_paragraph() in the same module.

     

Log in to post a comment.

MongoDB Logo MongoDB