Skip to content

Commit f2640c0

Browse files
committed
Move functionality to #formatLinks
1 parent fd418e9 commit f2640c0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

frontend/src/components/markdown-converter.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ const MarkdownConverter = class extends LitElement {
4747
// 4. Wrap any remaining http(s) URLs
4848
const linked = noLinks.replace(
4949
/(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/g,
50-
(url) => {
51-
// Ensure the destination URL has https:// at the beginning
52-
const href = url.startsWith('http') ? url : `https://${url}`;
53-
return `[${url}](${href})`;
54-
},
50+
(url) => `[${url}](${url})`,
5551
);
5652

5753
// 5. Restore links/images, inline code, then fenced code
@@ -103,6 +99,10 @@ const MarkdownConverter = class extends LitElement {
10399
this.querySelectorAll('a:not([target="_blank"])').forEach((link) => {
104100
link.setAttribute('target', '_blank');
105101
link.setAttribute('rel', 'noreferrer noopener');
102+
const href = link.getAttribute('href') || '';
103+
if (!href.startsWith('http')) {
104+
link.setAttribute('href', `https://${href}`);
105+
}
106106
link.innerHTML += ' <span class="sr-only top-0 -left-[1000px]">(opens in new tab)</span>';
107107
});
108108
}

0 commit comments

Comments
 (0)