Files
Reactive-Resume/packages/docx/src/link-utils.ts
T
Amruth Pillai 461d3c4e64 fix(docx): keep tel: links and drop script and style text
toSafeDocxLink accepted only http, https and mailto, so phone links in custom fields and rich text lost their link. The rich-text converter printed the text of script and style elements through its inline fallback; it now removes those elements after parsing.
2026-09-29 22:10:14 +02:00

21 lines
504 B
TypeScript

const SAFE_DOCX_LINK_SCHEMES = new Set(["http:", "https:", "mailto:", "tel:"]);
export function toSafeDocxLink(value: string): string | null {
const input = value.trim();
if (!input) return null;
if (input.startsWith("mailto:")) {
const email = input.slice("mailto:".length).trim();
if (!email) return null;
return `mailto:${email}`;
}
try {
const url = new URL(input);
if (!SAFE_DOCX_LINK_SCHEMES.has(url.protocol)) return null;
return url.toString();
} catch {
return null;
}
}