diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index c92053e..9f841d3 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -4,7 +4,7 @@ from wireviz.DataClasses import Connector, Cable from graphviz import Graph from wireviz import wv_colors -from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, nested, flatten2d, index_if_list +from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, nested, flatten2d, index_if_list, html_line_breaks, graphviz_line_breaks from collections import Counter from typing import List @@ -74,6 +74,8 @@ class Harness: infostring = f'{infostring}{attrib}, ' infostring = infostring[:-2] # remove trainling comma and space + infostring = html_line_breaks(infostring) + infostring_l = infostring if connector.ports_right else '' infostring_r = infostring if connector.ports_left else '' @@ -99,8 +101,8 @@ class Harness: f'MPN: {connector.manufacturer_part_number}' if connector.manufacturer_part_number else '', f'IPN: {connector.internal_part_number}' if connector.internal_part_number else ''] - attributes = [connector.type, - connector.subtype, + attributes = [graphviz_line_breaks(connector.type), + graphviz_line_breaks(connector.subtype), f'{connector.pincount}-pin' if connector.show_pincount else''] pinouts = [[], [], []] for pinnumber, pinname in zip(connector.pinnumbers, connector.pinout): @@ -111,7 +113,8 @@ class Harness: pinouts[0].append(f'{pinnumber}') if connector.ports_right: pinouts[2].append(f'{pinnumber}') - label = [connector.name if connector.show_name else '', identification, attributes, pinouts, connector.notes] + print(attributes) + label = [connector.name if connector.show_name else '', identification, attributes, pinouts, graphviz_line_breaks(connector.notes)] dot.node(key, label=nested(label)) if len(connector.loops) > 0: @@ -145,7 +148,7 @@ class Harness: f'IPN: {cable.internal_part_number}' if (cable.internal_part_number and not isinstance(cable.internal_part_number, list)) else ''] identification = list(filter(None, identification)) - attributes = [f'{cable.type}' if cable.type else '', + attributes = [html_line_breaks(cable.type) if cable.type else '', f'{len(cable.colors)}x' if cable.show_wirecount else '', f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else '', '+ S' if cable.shield else '', @@ -166,7 +169,7 @@ class Harness: html = f'{html}' # end identification row html = f'{html}' # attribute row for attrib in attributes: - html = f'{html}{attrib}' + html = f'{html}{attrib}' html = f'{html}' # attribute row html = f'{html}' # name+attributes table @@ -217,7 +220,7 @@ class Harness: html = f'{html}' # main table if cable.notes: - html = f'{html}{cable.notes}' # notes table + html = f'{html}{html_line_breaks(cable.notes)}' # notes table html = f'{html} ' # spacer at the end html = f'{html}' # main table diff --git a/src/wireviz/wv_helper.py b/src/wireviz/wv_helper.py index 69d6550..387e38c 100644 --- a/src/wireviz/wv_helper.py +++ b/src/wireviz/wv_helper.py @@ -69,3 +69,12 @@ def tuplelist2tsv(inp, header=None): # 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 html_line_breaks(inp): + return inp.replace('\n', '
') if isinstance(inp, str) else inp + +def graphviz_line_breaks(inp): + return inp.replace('\n', '\\l') if isinstance(inp, str) else inp # \l generates left-aligned new lines. http://www.graphviz.org/doc/info/attrs.html#k:escString + +def remove_line_breaks(inp): + return inp.replace('\n', ' ')