Skip to content

Commit

Permalink
Remove input text hyperlinks except in the HTML BOM
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
martonmiklos committed Sep 12, 2020
1 parent df90d83 commit a86a555
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion examples/ex05.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# daisy chain, variant 1
templates:
- &template_con
type: Molex KK 254
type: '<a href="https://www.molex.com/molex/products/family/kk_254_rpc_connector_system">Molex KK 254</a>'
subtype: female
pinlabels: [GND, VCC, SCL, SDA]
- &template_wire
Expand Down
12 changes: 6 additions & 6 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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
manufacturer_info_field, remove_links
from collections import Counter
from typing import List
from pathlib import Path
Expand Down Expand Up @@ -90,8 +90,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),
Expand Down Expand Up @@ -161,8 +161,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))],
Expand Down Expand Up @@ -204,7 +204,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)
Expand Down
8 changes: 6 additions & 2 deletions src/wireviz/wv_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

from typing import List
import re

awg_equiv_table = {
'0.09': '28',
Expand Down Expand Up @@ -106,15 +107,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] [^>]*>([^<]*)</[aA]>', r'\1', inp) if isinstance(inp, str) else inp

def html_line_breaks(inp):
return inp.replace('\n', '<br />') if isinstance(inp, str) else inp
return remove_links(inp).replace('\n', '<br />') if isinstance(inp, str) else inp

def graphviz_line_breaks(inp):
return inp.replace('\n', '\\n') if isinstance(inp, str) else inp # \n generates centered new lines. http://www.graphviz.org/doc/info/attrs.html#k:escString
Expand Down
8 changes: 4 additions & 4 deletions tutorial/tutorial08.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<a href="https://www.molex.com/">Molex</a>' # set manufacter name
mpn: '<a href="https://www.molex.com/molex/products/part-detail/crimp_housings/0022013047">22013047</a>' # set manufacturer part number
X2:
<<: *template1 # reuse template
pn: CON4 # set an internal part number
Expand Down Expand Up @@ -47,6 +47,6 @@ additional_bom_items:
designators:
- X2
- X3
manufacturer: generic company
mpn: Label1
manufacturer: '<a href="https://www.bradyid.com">Brady</a>'
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>'
pn: Label-ID-1

0 comments on commit a86a555

Please sign in to comment.