const escapeHtml = (value: string) => value .replaceAll('&', '&') .replaceAll('<', '<') .replaceAll('>', '>') .replaceAll('"', '"') .replaceAll("'", '''); export const parseEmailHtml = ( html: string, args: { href: string; userName: string; listingName: string; date: string; } ) => { // parse out any html scripts of type : or // and replace them with the appropriate component // return the parsed html // Values are escaped because names come from users and integrations. Function // replacers keep `$` sequences in a value from being read as patterns. const href = escapeHtml(args.href); return html .replaceAll( /<\/action-link-component>/g, () => `${href}` ) .replaceAll(/<\/user-name-component>/g, () => escapeHtml(args.userName) ) .replaceAll(/<\/listing-name-component>/g, () => escapeHtml(args.listingName) ) .replaceAll(/<\/date-component>/g, () => escapeHtml(args.date) ); };