From ad551f4f18dbd707d0ca550c2a5fec526982f352 Mon Sep 17 00:00:00 2001 From: Jakob Lykke Andersen Date: Sat, 23 Apr 2022 14:15:26 +0200 Subject: [PATCH] Pull lone literal_blocks out of paragraphs Fixes michaeljones/breathe#827 --- CHANGELOG.rst | 5 +++++ breathe/renderer/sphinxrenderer.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2c64c8d51..766b5e2a0 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,6 +3,11 @@ Change Log Inspired by `Keepachangelog.com `__. +- Unreleased + + - Pull lone literal blocks in paragraphs up to produce correct doctree. + `#833 `__ + - 2022-06-20 - **Breathe v4.34.0** - Treat .unparsed as plain text. diff --git a/breathe/renderer/sphinxrenderer.py b/breathe/renderer/sphinxrenderer.py index 894126bcd..1c9d28d0d 100644 --- a/breathe/renderer/sphinxrenderer.py +++ b/breathe/renderer/sphinxrenderer.py @@ -1502,6 +1502,23 @@ def visit_docpara(self, node) -> List[Node]: nodelist.extend(paramList) nodelist.extend(fields) + # And now all kinds of cleanup steps + # ---------------------------------- + + # trim trailing whitespace + while len(nodelist) != 0: + last = nodelist[-1] + if not isinstance(last, nodes.Text): + break + if last.astext().strip() != "": + break + nodelist.pop() + + # https://github.com/michaeljones/breathe/issues/827 + # verbatim nodes should not be in a paragraph: + if len(nodelist) == 1 and isinstance(nodelist[0], nodes.literal_block): + return nodelist + return [nodes.paragraph("", "", *nodelist)] def visit_docparblock(self, node) -> List[Node]: