Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for rowspan/colspan to tables #642

Merged
merged 3 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions breathe/parser/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,8 @@ class docEntryTypeSub(supermod.docEntryType):

node_type = "docentry"

def __init__(self, thead=None, para=None):
supermod.docEntryType.__init__(self, thead, para)
def __init__(self, thead=None, align=None, rowspan=None, colspan=None, para=None):
supermod.docEntryType.__init__(self, thead, align, rowspan, colspan, para)


supermod.docEntryType.subclass = docEntryTypeSub
Expand Down
23 changes: 22 additions & 1 deletion breathe/parser/compoundsuper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4641,8 +4641,11 @@ def buildChildren(self, child_, nodeName_):
class docEntryType(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, thead=None, para=None):
def __init__(self, thead=None, align=None, rowspan=None, colspan=None, para=None):
self.thead = thead
self.align = align
self.rowspan = rowspan
self.colspan = colspan
if para is None:
self.para = []
else:
Expand All @@ -4659,6 +4662,12 @@ def add_para(self, value): self.para.append(value)
def insert_para(self, index, value): self.para[index] = value
def get_thead(self): return self.thead
def set_thead(self, thead): self.thead = thead
def get_align(self): return self.align
def set_align(self, align): self.align = align
def get_rowspan(self): return self.rowspan
def set_rowspan(self, rowspan): self.rowspan = rowspan
def get_colspan(self): return self.colspan
def set_colspan(self, colspan): self.colspan = colspan
def export(self, outfile, level, namespace_='', name_='docEntryType', namespacedef_=''):
showIndent(outfile, level)
outfile.write('<%s%s %s' % (namespace_, name_, namespacedef_, ))
Expand All @@ -4673,6 +4682,12 @@ def export(self, outfile, level, namespace_='', name_='docEntryType', namespaced
def exportAttributes(self, outfile, level, namespace_='', name_='docEntryType'):
if self.thead is not None:
outfile.write(' thead=%s' % (quote_attrib(self.thead), ))
if self.align is not None:
outfile.write(' align=%s' % (quote_attrib(self.align), ))
if self.rowspan is not None:
outfile.write(' rowspan=%s' % (quote_attrib(self.rowspan), ))
if self.colspan is not None:
outfile.write(' colspan=%s' % (quote_attrib(self.colspan), ))
def exportChildren(self, outfile, level, namespace_='', name_='docEntryType'):
for para_ in self.para:
para_.export(outfile, level, namespace_, name_='para')
Expand All @@ -4692,6 +4707,12 @@ def build(self, node_):
def buildAttributes(self, attrs):
if attrs.get('thead'):
self.thead = attrs.get('thead').value
if attrs.get('align'):
self.align = attrs.get('align').value
if attrs.get('rowspan'):
self.rowspan = attrs.get('rowspan').value
if attrs.get('colspan'):
self.colspan = attrs.get('colspan').value
def buildChildren(self, child_, nodeName_):
if child_.nodeType == Node.ELEMENT_NODE and \
nodeName_ == 'para':
Expand Down
25 changes: 24 additions & 1 deletion breathe/renderer/sphinxrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,10 @@ def visit_docentry(self, node) -> List[Node]:
col += self.render_iterable(node.para)
if node.thead == 'yes':
col['heading'] = True
if node.rowspan:
col['morerows'] = int(node.rowspan) - 1
if node.colspan:
col['morecols'] = int(node.colspan) - 1
return [col]

def visit_docrow(self, node) -> List[Node]:
Expand All @@ -1688,7 +1692,26 @@ def visit_doctable(self, node) -> List[Node]:
colspec.attributes['colwidth'] = 'auto'
tgroup += colspec
table += tgroup
tgroup += self.render_iterable(node.row)
rows = self.render_iterable(node.row)

# this code depends on visit_docrow(), and expects the same elements used to
# "envelop" rows there, namely thead and tbody (eg it will need to be updated
# if Doxygen one day adds support for tfoot)

tags = {row.starttag(): [] for row in rows} # type: Dict[str, List]
for row in rows:
tags[row.starttag()].append(row.next_node())

def merge_row_types(root, elem, elems):
for node in elems:
elem += node
root += elem

for klass in [nodes.thead, nodes.tbody]:
obj = klass()
if obj.starttag() in tags:
merge_row_types(tgroup, obj, tags[obj.starttag()])

return [table]

def visit_mixedcontainer(self, node) -> List[Node]:
Expand Down