implemented opening of external links in new tab

This commit is contained in:
2025-09-08 21:39:15 +02:00
parent 6e3fa67ed1
commit 8107157f6a
6 changed files with 38 additions and 17 deletions

View File

@@ -1,3 +1,22 @@
const anchor_regex = /<a\s+([^>]*)href=['"]([^'"]+)['"]([^>]*)>/gi;
export function api(rel_path){
return `${location.protocol}//${location.host.replace('5173','8080')}/api/${rel_path}`;
}
export function target(code){
if (!code) return null;
let altered = code;
let match;
while(match = anchor_regex.exec(code)) {
const orig = match[0];
const href = match[2];
if (orig.includes('target=')) continue; // if there is already a target: skip
if (!href.includes('://')) continue; // if this is a relative path: skip
const anchor = '<a target="_blank" '+orig.substring(3);
altered = altered.replaceAll(orig,anchor);
}
return altered;
}