Skip to content

Commit e2e8bbf

Browse files
martonmiklos17o2
authored andcommitted
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.
1 parent e85ee5d commit e2e8bbf

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

examples/ex05.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# daisy chain, variant 1
22
templates:
33
- &template_con
4-
type: Molex KK 254
4+
type: '<a href="https://www.molex.com/molex/products/family/kk_254_rpc_connector_system">Molex KK 254</a>'
55
subtype: female
66
pinlabels: [GND, VCC, SCL, SDA]
77
- &template_wire

src/wireviz/Harness.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, \
99
nested_html_table, flatten2d, index_if_list, html_line_breaks, \
1010
clean_whitespace, open_file_read, open_file_write, html_colorbar, \
11-
html_image, html_caption, manufacturer_info_field, component_table_entry
11+
html_image, html_caption, manufacturer_info_field, component_table_entry, remove_links
1212
from collections import Counter
1313
from typing import List, Union
1414
from pathlib import Path
@@ -92,8 +92,8 @@ def create_graph(self) -> Graph:
9292

9393
html = []
9494

95-
rows = [[connector.name if connector.show_name else None],
96-
[f'P/N: {connector.pn}' if connector.pn else None,
95+
rows = [[remove_links(connector.name) if connector.show_name else None],
96+
[f'P/N: {remove_links(connector.pn)}' if connector.pn else None,
9797
html_line_breaks(manufacturer_info_field(connector.manufacturer, connector.mpn))],
9898
[html_line_breaks(connector.type),
9999
html_line_breaks(connector.subtype),
@@ -162,8 +162,8 @@ def create_graph(self) -> Graph:
162162
elif cable.gauge_unit.upper() == 'AWG':
163163
awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)'
164164

165-
rows = [[cable.name if cable.show_name else None],
166-
[f'P/N: {cable.pn}' if (cable.pn and not isinstance(cable.pn, list)) else None,
165+
rows = [[remove_links(cable.name) if cable.show_name else None],
166+
[f'P/N: {remove_links(cable.pn)}' if (cable.pn and not isinstance(cable.pn, list)) else None,
167167
html_line_breaks(manufacturer_info_field(
168168
cable.manufacturer if not isinstance(cable.manufacturer, list) else None,
169169
cable.mpn if not isinstance(cable.mpn, list) else None))],
@@ -205,7 +205,7 @@ def create_graph(self) -> Graph:
205205
# create a list of wire parameters
206206
wireidentification = []
207207
if isinstance(cable.pn, list):
208-
wireidentification.append(f'P/N: {cable.pn[i - 1]}')
208+
wireidentification.append(f'P/N: {remove_links(cable.pn[i - 1])}')
209209
manufacturer_info = manufacturer_info_field(
210210
cable.manufacturer[i - 1] if isinstance(cable.manufacturer, list) else None,
211211
cable.mpn[i - 1] if isinstance(cable.mpn, list) else None)

src/wireviz/wv_helper.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from wireviz import wv_colors
55
from typing import List
6+
import re
67

78
awg_equiv_table = {
89
'0.09': '28',
@@ -136,15 +137,18 @@ def tuplelist2tsv(inp, header=None):
136137
inp.insert(0, header)
137138
inp = flatten2d(inp)
138139
for row in inp:
139-
output = output + '\t'.join(str(item) for item in row) + '\n'
140+
output = output + '\t'.join(str(remove_links(item)) for item in row) + '\n'
140141
return output
141142

142143
# Return the value indexed if it is a list, or simply the value otherwise.
143144
def index_if_list(value, index):
144145
return value[index] if isinstance(value, list) else value
145146

147+
def remove_links(inp):
148+
return re.sub(r'<[aA] [^>]*>([^<]*)</[aA]>', r'\1', inp) if isinstance(inp, str) else inp
149+
146150
def html_line_breaks(inp):
147-
return inp.replace('\n', '<br />') if isinstance(inp, str) else inp
151+
return remove_links(inp).replace('\n', '<br />') if isinstance(inp, str) else inp
148152

149153
def clean_whitespace(inp):
150154
return ' '.join(inp.split()).replace(' ,', ',') if isinstance(inp, str) else inp

tutorial/tutorial08.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ connectors:
33
type: Molex KK 254
44
pincount: 4
55
subtype: female
6-
manufacturer: Molex # set manufacter name
7-
mpn: 22013047 # set manufacturer part number
6+
manufacturer: '<a href="https://www.molex.com/">Molex</a>' # set manufacter name
7+
mpn: '<a href="https://www.molex.com/molex/products/part-detail/crimp_housings/0022013047">22013047</a>' # set manufacturer part number
88
# add a list of additional components to a part (shown in graph)
99
additional_components:
1010
-
@@ -63,6 +63,6 @@ additional_bom_items:
6363
designators:
6464
- X2
6565
- X3
66-
manufacturer: generic company
67-
mpn: Label1
66+
manufacturer: '<a href="https://www.bradyid.com">Brady</a>'
67+
mpn: '<a href="https://www.bradyid.com/wire-cable-labels/bmp71-bmp61-m611-tls-2200-nylon-cloth-wire-general-id-labels-cps-2958789">B-499</a>'
6868
pn: Label-ID-1

0 commit comments

Comments
 (0)