Remove border between image and caption
Adding helper function for each of these with a leading <tdX> tag that instructs nested_html_table() to inject attributes to the <td> tag.
This commit is contained in:
parent
c8c4005487
commit
0cb7118930
@ -8,7 +8,7 @@ from wireviz.wv_colors import get_color_hex
|
||||
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, \
|
||||
nested_html_table, flatten2d, index_if_list, html_line_breaks, \
|
||||
graphviz_line_breaks, remove_line_breaks, open_file_read, open_file_write, \
|
||||
manufacturer_info_field
|
||||
html_image, html_caption, manufacturer_info_field
|
||||
from collections import Counter
|
||||
from typing import List
|
||||
from pathlib import Path
|
||||
@ -98,8 +98,8 @@ class Harness:
|
||||
f'{connector.pincount}-pin' if connector.show_pincount else None,
|
||||
connector.color, '<!-- colorbar -->' if connector.color else None],
|
||||
'<!-- connector table -->' if connector.style != 'simple' else None,
|
||||
[f'<img src="{connector.image}"/>' if connector.image else None],
|
||||
[html_line_breaks(connector.caption)],
|
||||
[html_image(connector)],
|
||||
[html_caption(connector)],
|
||||
[html_line_breaks(connector.notes)]]
|
||||
html.extend(nested_html_table(rows))
|
||||
|
||||
@ -175,8 +175,8 @@ class Harness:
|
||||
f'{cable.length} m' if cable.length > 0 else None,
|
||||
cable.color, '<!-- colorbar -->' if cable.color else None],
|
||||
'<!-- wire table -->',
|
||||
[f'<img src="{cable.image}"/>' if cable.image else None],
|
||||
[html_line_breaks(cable.caption)],
|
||||
[html_image(cable)],
|
||||
[html_caption(cable)],
|
||||
[html_line_breaks(cable.notes)]]
|
||||
html.extend(nested_html_table(rows))
|
||||
|
||||
|
||||
@ -34,6 +34,7 @@ def nested_html_table(rows):
|
||||
# input: list, each item may be scalar or list
|
||||
# output: a parent table with one child table per parent item that is list, and one cell per parent item that is scalar
|
||||
# purpose: create the appearance of one table, where cell widths are independent between rows
|
||||
# attributes in any leading <tdX> inside a list are injected into to the preceeding <td> tag
|
||||
html = []
|
||||
html.append('<table border="0" cellspacing="0" cellpadding="0">')
|
||||
for row in rows:
|
||||
@ -43,7 +44,8 @@ def nested_html_table(rows):
|
||||
html.append(' <table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr>')
|
||||
for cell in row:
|
||||
if cell is not None:
|
||||
html.append(f' <td balign="left">{cell}</td>')
|
||||
# Inject attributes to the preceeding <td> tag where needed
|
||||
html.append(f' <td balign="left">{cell}</td>'.replace('><tdX', ''))
|
||||
html.append(' </tr></table>')
|
||||
html.append(' </td></tr>')
|
||||
elif row is not None:
|
||||
@ -53,6 +55,12 @@ def nested_html_table(rows):
|
||||
html.append('</table>')
|
||||
return html
|
||||
|
||||
def html_image(node):
|
||||
return f'''<tdX{' sides="TLR"' if node.caption else ''}><img src="{node.image}"/>''' if node.image else None
|
||||
|
||||
def html_caption(node):
|
||||
return f'''<tdX{' sides="LRB"' if node.image else ''}>{html_line_breaks(node.caption)}''' if node.caption else None
|
||||
|
||||
|
||||
def expand(yaml_data):
|
||||
# yaml_data can be:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user