Markdown -> Semble importer
1export function normalizeSourceUrl(input: string): string {
2 const trimmed = input.trim();
3 if (!trimmed) return trimmed;
4
5 try {
6 const url = new URL(trimmed);
7 if (url.hostname === "gist.github.com") {
8 const [user, gistId] = url.pathname.split("/").filter(Boolean);
9 if (user && gistId) {
10 return `https://gist.githubusercontent.com/${user}/${gistId}/raw`;
11 }
12 }
13 if (url.hostname === "gist.githubusercontent.com" && url.pathname.includes("/raw")) {
14 return trimmed;
15 }
16 return trimmed;
17 } catch {
18 return trimmed;
19 }
20}
21
22export function isProbablyUrl(input: string): boolean {
23 return /^(https?:\/\/|at:\/\/)/i.test(input.trim());
24}