Skip to content

Commit 39fc0c4

Browse files
authored
Create hyperlinks for URLs (#339)
* Create anchor (link) tags around strings that look like a URL * Handle anchor (link) tags when copying/exporting table content * Allow for exporting hyperlinks to CSV * Revert "Allow for exporting hyperlinks to CSV" This reverts commit 9ead72c. * Check URL for validity * Relax URL-matching regex As suggested by @qu1ck, use https://gitlab.com/kicad/code/kicad/-/blob/2f8cc845513b918e219f32733a210bf458138f91/kicad/pcm/schemas/pcm.v1.schema.json#L287 as a reference, but fix these issues: * remove the single period (any char) in the http(s) part to allow single-character host names, such as http://a (valid, brings up the default page of the webserver on host 'a') * add missing parenthesis (group) around everything between ^ and $ for the alternative (|) to work as expected (the original regex will match file:// in the middle of the string, as the regex matches anything that *either* *begins* with http(s):// *or* *ends* with a file://... URL scheme) * Move URL-matching regex definition to top of populateBomBody() * Iterate directly over valueSet * Use backtick string notation
1 parent db0f8ee commit 39fc0c4

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

InteractiveHtmlBom/web/ibom.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ function populateBomHeader(placeHolderColumn = null, placeHolderElements = null)
552552
}
553553

554554
function populateBomBody(placeholderColumn = null, placeHolderElements = null) {
555+
const urlRegex = /^(https?:\/\/[^\s\/$.?#][^\s]*|file:\/\/([a-zA-Z]:|\/)[^\x00]+)$/;
555556
while (bom.firstChild) {
556557
bom.removeChild(bom.firstChild);
557558
}
@@ -659,7 +660,16 @@ function populateBomBody(placeholderColumn = null, placeHolderElements = null) {
659660
var valueSet = new Set();
660661
references.map(r => r[1]).forEach((id) => valueSet.add(pcbdata.bom.fields[id][field_index]));
661662
td = document.createElement("TD");
662-
td.innerHTML = highlightFilter(Array.from(valueSet).join(", "));
663+
var output = new Array();
664+
for (let item of valueSet) {
665+
const visible = highlightFilter(item);
666+
if (item.match(urlRegex)) {
667+
output.push(`<a href="${item}" target="_blank">${visible}</a>`);
668+
} else {
669+
output.push(visible);
670+
}
671+
}
672+
td.innerHTML = output.join(", ");
663673
tr.appendChild(td);
664674
}
665675
});

InteractiveHtmlBom/web/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function saveBomTable(output) {
8585
if (node.checked) {
8686
val += '✓';
8787
}
88-
} else if (node.nodeName == "MARK") {
88+
} else if ((node.nodeName == "MARK") || (node.nodeName == "A")) {
8989
val += node.firstChild.nodeValue;
9090
} else {
9191
val += node.nodeValue;

0 commit comments

Comments
 (0)