Resolve edge case of empty HTML tables
This commit is contained in:
parent
8ea8248721
commit
2a62dae9ee
@ -14,6 +14,8 @@ def nested_html_table(rows: List[Union[str, List[Optional[str]], None]], table_a
|
|||||||
# attributes in any leading <tdX> inside a list are injected into to the preceeding <td> tag
|
# attributes in any leading <tdX> inside a list are injected into to the preceeding <td> tag
|
||||||
html = []
|
html = []
|
||||||
html.append(f'<table border="0" cellspacing="0" cellpadding="0"{table_attrs or ""}>')
|
html.append(f'<table border="0" cellspacing="0" cellpadding="0"{table_attrs or ""}>')
|
||||||
|
|
||||||
|
num_rows = 0
|
||||||
for row in rows:
|
for row in rows:
|
||||||
if isinstance(row, List):
|
if isinstance(row, List):
|
||||||
if len(row) > 0 and any(row):
|
if len(row) > 0 and any(row):
|
||||||
@ -25,10 +27,14 @@ def nested_html_table(rows: List[Union[str, List[Optional[str]], None]], table_a
|
|||||||
html.append(f' <td balign="left">{cell}</td>'.replace('><tdX', ''))
|
html.append(f' <td balign="left">{cell}</td>'.replace('><tdX', ''))
|
||||||
html.append(' </tr></table>')
|
html.append(' </tr></table>')
|
||||||
html.append(' </td></tr>')
|
html.append(' </td></tr>')
|
||||||
|
num_rows = num_rows + 1
|
||||||
elif row is not None:
|
elif row is not None:
|
||||||
html.append(' <tr><td>')
|
html.append(' <tr><td>')
|
||||||
html.append(f' {row}')
|
html.append(f' {row}')
|
||||||
html.append(' </td></tr>')
|
html.append(' </td></tr>')
|
||||||
|
num_rows = num_rows + 1
|
||||||
|
if num_rows == 0: # empty table
|
||||||
|
html.append('<tr><td></td></tr>') # generate empty cell to avoid GraphViz errors
|
||||||
html.append('</table>')
|
html.append('</table>')
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user