Skip to content

Commit

Permalink
Merge branch 'fix_666' of https://github.com/jakobandersen/breathe
Browse files Browse the repository at this point in the history
  • Loading branch information
vermeeren committed Apr 23, 2021
2 parents 67a50c2 + 1cf8fef commit 917ce26
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 43 deletions.
3 changes: 1 addition & 2 deletions breathe/renderer/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@
from sphinx.application import Sphinx

import os
import six
from typing import Any, Callable, Dict, List


Expand Down Expand Up @@ -325,7 +324,7 @@ def __call__(self, node_stack) -> str:
except AttributeError as e:
# Horrible hack to silence errors on filtering unicode objects
# until we fix the parsing
if type(data_object) == six.text_type:
if type(data_object) == str:
return "unicode"
else:
raise e
Expand Down
5 changes: 1 addition & 4 deletions breathe/renderer/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
"""

import six


class NoParameterNamesMask:
def __init__(self, data_object) -> None:
self.data_object = data_object
Expand All @@ -46,7 +43,7 @@ def mask(self, data_object):
except AttributeError as e:
# Horrible hack to silence errors on filtering unicode objects
# until we fix the parsing
if isinstance(data_object, six.text_type):
if isinstance(data_object, str):
node_type = "unicode"
else:
raise e
Expand Down
83 changes: 48 additions & 35 deletions breathe/renderer/sphinxrenderer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sphinx

from breathe.parser import DoxygenCompoundParser
from breathe.parser import DoxygenCompoundParser, compoundsuper
from breathe.project import ProjectInfo
from breathe.renderer import RenderContext
from breathe.renderer.filter import Filter
Expand Down Expand Up @@ -28,7 +28,6 @@
cs = None

import re
import six
import textwrap
from typing import Callable, cast, Dict, List, Optional, Tuple, Type, Union # noqa

Expand Down Expand Up @@ -368,7 +367,7 @@ def to_string(node):
if node is not None:
for p in node.content_:
value = p.value
if not isinstance(value, six.text_type):
if not isinstance(value, str):
value = value.valueOf_
result.append(value)
return ' '.join(result)
Expand Down Expand Up @@ -557,7 +556,7 @@ def get_filename(node) -> Optional[str]:
node = node_stack[0]
# An enumvalue node doesn't have location, so use its parent node for detecting
# the domain instead.
if isinstance(node, six.string_types) or node.node_type == "enumvalue":
if isinstance(node, str) or node.node_type == "enumvalue":
node = node_stack[1]
filename = get_filename(node)
if not filename and node.node_type == "compound":
Expand Down Expand Up @@ -913,29 +912,6 @@ def render_declaration(self, node, declaration=None, description=None, **kwargs)
contentnode.extend(description)
return nodes

def visit_unicode(self, node) -> List[Node]:
# Skip any nodes that are pure whitespace
# Probably need a better way to do this as currently we're only doing
# it skip whitespace between higher-level nodes, but this will also
# skip any pure whitespace entries in actual content nodes
#
# We counter that second issue slightly by allowing through single white spaces
#
if node.strip():
delimiter = None
if "<linebreak>" in node:
delimiter = "<linebreak>"
elif "\n" in node:
delimiter = "\n"
if delimiter:
# Render lines as paragraphs because RST doesn't have line breaks.
return [nodes.paragraph('', '', nodes.Text(line))
for line in node.split(delimiter) if line.strip()]
return [nodes.Text(node)]
if node == six.u(" "):
return [nodes.Text(node)]
return []

def visit_doxygen(self, node) -> List[Node]:
nodelist = []

Expand Down Expand Up @@ -1388,7 +1364,18 @@ def visit_docpara(self, node) -> List[Node]:
if self.context and self.context.directive_args[0] == "doxygenpage":
nodelist.extend(self.render_iterable(node.ordered_children))
else:
nodelist.extend(self.render_iterable(node.content))
contentNodeCands = self.render_iterable(node.content)
# if there are consecutive nodes.Text we should collapse them
# and rerender them to ensure the right paragraphifaction
contentNodes = [] # type: List[Node]
for n in contentNodeCands:
if len(contentNodes) != 0 and isinstance(contentNodes[-1], nodes.Text):
if isinstance(n, nodes.Text):
prev = contentNodes.pop()
contentNodes.extend(self.render_string(prev.astext() + n.astext()))
continue # we have handled this node
contentNodes.append(n)
nodelist.extend(contentNodes)
nodelist.extend(self.render_iterable(node.images))

paramList = self.render_iterable(node.parameterlist)
Expand Down Expand Up @@ -1797,7 +1784,7 @@ def merge_row_types(root, elem, elems):

return [table]

def visit_mixedcontainer(self, node) -> List[Node]:
def visit_mixedcontainer(self, node: compoundsuper.MixedContainer) -> List[Node]:
return self.render_optional(node.getValue())

def visit_description(self, node) -> List[Node]:
Expand Down Expand Up @@ -2039,7 +2026,7 @@ def visit_param(self, node) -> List[Node]:
if node.type_:
type_nodes = self.render(node.type_)
# Render keywords as annotations for consistency with the cpp domain.
if len(type_nodes) > 0 and isinstance(type_nodes[0], six.text_type):
if len(type_nodes) > 0 and isinstance(type_nodes[0], str):
first_node = type_nodes[0]
for keyword in ['typename', 'class']:
if first_node.startswith(keyword + ' '):
Expand Down Expand Up @@ -2215,7 +2202,33 @@ def dispatch_memberdef(self, node) -> List[Node]:
"docentry": visit_docentry,
}

def render(self, node, context: Optional[RenderContext] = None) -> List[Node]:
def render_string(self, node: str) -> List[Union[nodes.Text, nodes.paragraph]]:
# Skip any nodes that are pure whitespace
# Probably need a better way to do this as currently we're only doing
# it skip whitespace between higher-level nodes, but this will also
# skip any pure whitespace entries in actual content nodes
#
# We counter that second issue slightly by allowing through single white spaces
#
stripped = node.strip()
if stripped:
delimiter = None
if "<linebreak>" in stripped:
delimiter = "<linebreak>"
elif "\n" in stripped:
delimiter = "\n"
if delimiter:
# Render lines as paragraphs because RST doesn't have line breaks.
return [nodes.paragraph('', '', nodes.Text(line.strip()))
for line in node.split(delimiter) if line.strip()]
# importantly, don't strip whitespace as visit_docpara uses it to collapse
# consecutive nodes.Text and rerender them with this function.
return [nodes.Text(node)]
if node == " ":
return [nodes.Text(node)]
return []

def render(self, node: Node, context: Optional[RenderContext] = None) -> List[Node]:
if context is None:
self.context = cast(RenderContext, self.context)
context = self.context.create_child_context(node)
Expand All @@ -2224,18 +2237,18 @@ def render(self, node, context: Optional[RenderContext] = None) -> List[Node]:
self.context = cast(RenderContext, self.context)
if not self.filter_.allow(self.context.node_stack):
pass
elif isinstance(node, six.string_types):
result = self.visit_unicode(node)
elif isinstance(node, str):
result = self.render_string(node)
else:
method = SphinxRenderer.methods.get(node.node_type, SphinxRenderer.visit_unknown)
result = method(self, node)
return result

def render_optional(self, node) -> List[Node]:
def render_optional(self, node: Node) -> List[Node]:
"""Render a node that can be None."""
return self.render(node) if node else []

def render_iterable(self, iterable) -> List[Node]:
def render_iterable(self, iterable: List[Node]) -> List[Node]:
output = []
for entry in iterable:
output.extend(self.render(entry))
Expand Down
2 changes: 1 addition & 1 deletion examples/tinyxml/tinyxml.h
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ class TiXmlPrinter : public TiXmlVisitor
void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; }
/// Query the indention string.
const char* Indent() { return indent.c_str(); }
/** Set the line breaking string. By default set to newline (\n).
/** Set the line breaking string. By default set to newline (\c \n).
Some operating systems prefer other characters, or can be
set to the null/empty string for no indentation.
*/
Expand Down
1 change: 0 additions & 1 deletion requirements/production.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ Jinja2>=2.7.3
MarkupSafe>=0.23
Pygments>=1.6
Sphinx>=3.0,<5
six>=1.9.0

0 comments on commit 917ce26

Please sign in to comment.