mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-10-03 18:23:47 +10:00
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.
21 lines
504 B
TypeScript
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;
|
|
}
|
|
}
|