File
Blob: src/client/lib/email-html/serialize.ts
| 1 | function escapeHtmlAttribute(value: string) { |
| 2 | return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">"); |
| 3 | } |
| 4 | |
| 5 | export function serializeBodyAttributes(body: HTMLElement) { |
| 6 | const attributes = ["dir", "lang", "style"] |
| 7 | .map((name) => { |
| 8 | const value = body.getAttribute(name); |
| 9 | if (!value) { |
| 10 | return null; |
| 11 | } |
| 12 | |
| 13 | return `${name}="${escapeHtmlAttribute(value)}"`; |
| 14 | }) |
| 15 | .filter((value): value is string => Boolean(value)); |
| 16 | |
| 17 | return attributes.join(" "); |
| 18 | } |
| 19 | |
| 20 | export function serializeStyleTag(value: string) { |
| 21 | return `<style>${value.replace(/<\/style/gi, "<\\/style")}</style>`; |
| 22 | } |