feat: send links as [URL]...[/URL] like the native clients

Native TeamSpeak clients wrap links in [URL] tags when sending and only
link tagged ones, so a bare URL typed in the web client stayed plain
text for them. Chat and offline messages now wrap bare http(s) URLs;
links that are already tagged are left alone.

Also stops the collected-URLs list from picking up "[/URL]" as part of
a link, by sharing the renderer's URL pattern.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Opus 5.5 committed 2026-10-04 10:32:10 +00:00
1 parent e37e090ab2
commit 839e26e4a3
2 files changed
+12 -7

No files matched your search

+8 -1
View File
@@ -7,7 +7,9 @@ import { Fragment, type ReactNode } from "react";
// render as plain text ([img] as a link, so it never loads a remote image).
const TAG_REGEX = /\[(\/?)(b|i|u|s|url|img|color)(?:=([^\]]*))?\]/gi;
const BARE_URL_REGEX = /https?:\/\/[^\s<>"\[\]]+/g;
export const BARE_URL_REGEX = /https?:\/\/[^\s<>"\[\]]+/g;
// An already-tagged link (left alone) or a bare URL (wrapped).
const WRAP_REGEX = new RegExp(`(\\[(url|img)(?:=[^\\]]*)?\\][\\s\\S]*?\\[\\/\\2\\])|${BARE_URL_REGEX.source}`, "gi");
const COLOR_REGEX = /^(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z]+)$/i;
interface Node {
@@ -99,3 +101,8 @@ export function renderBbcode(text: string): ReactNode {
if (last < text.length) stack[stack.length - 1].children.push(text.slice(last));
return render(root, 0);
}
// Outgoing: native clients send links as [URL]...[/URL] and only link those.
export function wrapUrls(text: string): string {
return text.replace(WRAP_REGEX, (m, tagged) => (tagged ? m : `[URL]${m}[/URL]`));
}