Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
r-richardson committed Oct 2, 2024
1 parent d621070 commit 83285ce
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions assets/javascripts/openqa.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,19 +577,45 @@ function renderComments(row) {
}

function renderHttpUrlAsLink(value) {
const span = document.createElement('span');
for (let match; (match = value.match(/https?:\/\/[^\s,]*/)); ) {
const url = match[0];
const link = document.createElement('a');
link.href = url;
link.target = 'blank';
link.appendChild(document.createTextNode(url));
span.appendChild(document.createTextNode(value.substr(0, match.index)));
span.appendChild(link);
value = value.substr(match.index + url.length);
if (!value) {
return value;
}
if (Array.isArray(value)) {
const fragment = document.createDocumentFragment();
value.forEach((item, index) => {
fragment.append(renderHttpUrlAsLink(item));
if (index < value.length - 1) {
fragment.append(', '); // Add a separator between items
}
});
return fragment;
}
if (typeof value !== 'string') {
value = String(value);
}
const urlRegex = /https?:\/\/[^\s,]*/g;
const matches = value.match(urlRegex);
if (matches) {
const fragment = document.createDocumentFragment();
let lastIndex = 0;
for (const match of matches) {
const index = value.indexOf(match, lastIndex);
if (index > lastIndex) {
fragment.append(value.substring(lastIndex, index));
}
const a = document.createElement('a');
a.href = match;
a.textContent = match;
fragment.append(a);
lastIndex = index + match.length;
}
if (lastIndex < value.length) {
fragment.append(value.substring(lastIndex));
}
return fragment;
} else {
return value;
}
span.appendChild(document.createTextNode(value));
return span;
}

function getXhrError(jqXHR, textStatus, errorThrown) {
Expand Down

0 comments on commit 83285ce

Please sign in to comment.