Convert urls in logs to links (#3904)

This commit is contained in:
Anbraten 2024-07-13 21:34:35 +02:00 committed by GitHub
parent 1c0073f984
commit f61bff2fff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -180,11 +180,21 @@ function formatTime(time?: number): string {
return time === undefined ? '' : `${time}s`;
}
function processText(text: string): string {
const urlRegex = /https?:\/\/\S+/g;
let txt = ansiUp.value.ansi_to_html(`${decode(text)}\n`);
txt = txt.replace(
urlRegex,
(url) => `<a href="${url}" target="_blank" rel="noopener noreferrer" class="underline">${url}</a>`,
);
return txt;
}
function writeLog(line: Partial<LogLine>) {
logBuffer.value.push({
index: line.index ?? 0,
number: (line.index ?? 0) + 1,
text: ansiUp.value.ansi_to_html(`${decode(line.text ?? '')}\n`),
text: processText(line.text ?? ''),
time: line.time ?? 0,
type: null, // TODO: implement way to detect errors and warnings
});