From a64809cfaba737a6b46ee2e7036cc553d123fe6a Mon Sep 17 00:00:00 2001 From: Ashish Sadanandan Date: Thu, 31 May 2018 12:41:56 -0600 Subject: [PATCH] Render newlines as separate paragraphs Line breaks in Doxygen documentation are not being rendered correctly. Given the following C++ class definition /*! * @brief Lorem ipsum dolor sit amet */ class foo { public: /* Fields */ uint8_t bar; /*!< @brief consectetur adipiscing elit
Range: 0 .. 10
Default: 0*/ }; // class foo The corresponding XML output for the `bar` data member is uint8_t uint8_t foo::bar bar consectetur adipiscing elit Range: 0 .. 10 Default: 0 The `` tags, which appear as newline characters in the node argument's text in the call to `SphinxRenderer.visit_unicode`, do not get rendered as paragraphs. The corresponding Sphinx HTML is

consectetur adipiscing elit Range: 0 .. 10 Default: 0

This commit wraps each line in multiline comments in a paragraph so it gets rendered correctly. After applying this change, the Sphinx HTML is rendered as follows

consectetur adipiscing elit

Range: 0 .. 10

Default: 0

--- breathe/renderer/sphinxrenderer.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/breathe/renderer/sphinxrenderer.py b/breathe/renderer/sphinxrenderer.py index c576d4f5..4b072897 100644 --- a/breathe/renderer/sphinxrenderer.py +++ b/breathe/renderer/sphinxrenderer.py @@ -431,11 +431,16 @@ def visit_unicode(self, node): # We counter that second issue slightly by allowing through single white spaces # if node.strip(): - if "" not in node: - return [self.node_factory.Text(node)] - # Render lines as paragraphs because RST doesn't have line breaks. - return [self.node_factory.paragraph('', '', self.node_factory.Text(line)) - for line in node.split("")] + delimiter = None + if "" in node: + delimiter = "" + elif "\n" in node: + delimiter = "\n" + if delimiter: + # Render lines as paragraphs because RST doesn't have line breaks. + return [self.node_factory.paragraph('', '', self.node_factory.Text(line)) + for line in node.split(delimiter) if line.strip()] + return [self.node_factory.Text(node)] if node == six.u(" "): return [self.node_factory.Text(node)] return []