From e2e8bbfb913902d511a83e88db7316049b5b48ca Mon Sep 17 00:00:00 2001 From: Miklos Marton Date: Wed, 9 Sep 2020 17:34:12 +0200 Subject: [PATCH] Remove input text hyperlinks except in the HTML BOM GraphViz does not support the a HTML tag when generating the tables for the cables/connectors, so this change will remove these tags for the graph generation. However for the HTML BOM output table these links will be generated. --- examples/ex05.yml | 2 +- src/wireviz/Harness.py | 12 ++++++------ src/wireviz/wv_helper.py | 8 ++++++-- tutorial/tutorial08.yml | 8 ++++---- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/examples/ex05.yml b/examples/ex05.yml index fd776f98..98a1a340 100644 --- a/examples/ex05.yml +++ b/examples/ex05.yml @@ -1,7 +1,7 @@ # daisy chain, variant 1 templates: - &template_con - type: Molex KK 254 + type: 'Molex KK 254' subtype: female pinlabels: [GND, VCC, SCL, SDA] - &template_wire diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 437ac205..835ed651 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -8,7 +8,7 @@ from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, \ nested_html_table, flatten2d, index_if_list, html_line_breaks, \ clean_whitespace, open_file_read, open_file_write, html_colorbar, \ - html_image, html_caption, manufacturer_info_field, component_table_entry + html_image, html_caption, manufacturer_info_field, component_table_entry, remove_links from collections import Counter from typing import List, Union from pathlib import Path @@ -92,8 +92,8 @@ def create_graph(self) -> Graph: html = [] - rows = [[connector.name if connector.show_name else None], - [f'P/N: {connector.pn}' if connector.pn else None, + rows = [[remove_links(connector.name) if connector.show_name else None], + [f'P/N: {remove_links(connector.pn)}' if connector.pn else None, html_line_breaks(manufacturer_info_field(connector.manufacturer, connector.mpn))], [html_line_breaks(connector.type), html_line_breaks(connector.subtype), @@ -162,8 +162,8 @@ def create_graph(self) -> Graph: elif cable.gauge_unit.upper() == 'AWG': awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)' - rows = [[cable.name if cable.show_name else None], - [f'P/N: {cable.pn}' if (cable.pn and not isinstance(cable.pn, list)) else None, + rows = [[remove_links(cable.name) if cable.show_name else None], + [f'P/N: {remove_links(cable.pn)}' if (cable.pn and not isinstance(cable.pn, list)) else None, html_line_breaks(manufacturer_info_field( cable.manufacturer if not isinstance(cable.manufacturer, list) else None, cable.mpn if not isinstance(cable.mpn, list) else None))], @@ -205,7 +205,7 @@ def create_graph(self) -> Graph: # create a list of wire parameters wireidentification = [] if isinstance(cable.pn, list): - wireidentification.append(f'P/N: {cable.pn[i - 1]}') + wireidentification.append(f'P/N: {remove_links(cable.pn[i - 1])}') manufacturer_info = manufacturer_info_field( cable.manufacturer[i - 1] if isinstance(cable.manufacturer, list) else None, cable.mpn[i - 1] if isinstance(cable.mpn, list) else None) diff --git a/src/wireviz/wv_helper.py b/src/wireviz/wv_helper.py index 79722bd3..9d785229 100644 --- a/src/wireviz/wv_helper.py +++ b/src/wireviz/wv_helper.py @@ -3,6 +3,7 @@ from wireviz import wv_colors from typing import List +import re awg_equiv_table = { '0.09': '28', @@ -136,15 +137,18 @@ def tuplelist2tsv(inp, header=None): inp.insert(0, header) inp = flatten2d(inp) for row in inp: - output = output + '\t'.join(str(item) for item in row) + '\n' + output = output + '\t'.join(str(remove_links(item)) for item in row) + '\n' return output # Return the value indexed if it is a list, or simply the value otherwise. def index_if_list(value, index): return value[index] if isinstance(value, list) else value +def remove_links(inp): + return re.sub(r'<[aA] [^>]*>([^<]*)', r'\1', inp) if isinstance(inp, str) else inp + def html_line_breaks(inp): - return inp.replace('\n', '
') if isinstance(inp, str) else inp + return remove_links(inp).replace('\n', '
') if isinstance(inp, str) else inp def clean_whitespace(inp): return ' '.join(inp.split()).replace(' ,', ',') if isinstance(inp, str) else inp diff --git a/tutorial/tutorial08.yml b/tutorial/tutorial08.yml index 27cd3102..2dc55443 100644 --- a/tutorial/tutorial08.yml +++ b/tutorial/tutorial08.yml @@ -3,8 +3,8 @@ connectors: type: Molex KK 254 pincount: 4 subtype: female - manufacturer: Molex # set manufacter name - mpn: 22013047 # set manufacturer part number + manufacturer: 'Molex' # set manufacter name + mpn: '22013047' # set manufacturer part number # add a list of additional components to a part (shown in graph) additional_components: - @@ -63,6 +63,6 @@ additional_bom_items: designators: - X2 - X3 - manufacturer: generic company - mpn: Label1 + manufacturer: 'Brady' + mpn: 'B-499' pn: Label-ID-1