From 1d3e7e4522eed2e2fb21263eaeb6a12a91b5bd85 Mon Sep 17 00:00:00 2001 From: KV Date: Mon, 3 Aug 2020 23:12:31 +0200 Subject: [PATCH] Remove border between image and caption Adding helper function for each of these with a leading tag that instructs nested_html_table() to inject attributes to the tag. --- src/wireviz/Harness.py | 10 +++++----- src/wireviz/wv_helper.py | 10 +++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 6594ce2..31a9b69 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -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, '' if connector.color else None], '' if connector.style != 'simple' else None, - [f'' 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, '' if cable.color else None], '', - [f'' 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)) diff --git a/src/wireviz/wv_helper.py b/src/wireviz/wv_helper.py index 102acea..fe4b7a3 100644 --- a/src/wireviz/wv_helper.py +++ b/src/wireviz/wv_helper.py @@ -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 inside a list are injected into to the preceeding tag html = [] html.append('') for row in rows: @@ -43,7 +44,8 @@ def nested_html_table(rows): html.append('
') for cell in row: if cell is not None: - html.append(f'') + # Inject attributes to the preceeding '.replace('>
{cell} tag where needed + html.append(f'{cell}
') html.append('') elif row is not None: @@ -53,6 +55,12 @@ def nested_html_table(rows): html.append('') return html +def html_image(node): + return f'''''' if node.image else None + +def html_caption(node): + return f'''{html_line_breaks(node.caption)}''' if node.caption else None + def expand(yaml_data): # yaml_data can be: