Pages list and Tiptap editor (ported from babyboo) with image upload on save, the FORM event picker, field errors at their fields, delete confirmation, unsaved-edits guard and a draft preview. The public page /p/<company>/<slug> renders on the server with metadata, sanitize-html, the company's logo and accent, and the sign-up form with UTM tags. Companies get branding; the event lead detail shows the web page and campaign. Labels in English and Chinese. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
25 lines
1.2 KiB
TypeScript
25 lines
1.2 KiB
TypeScript
import sanitizeHtml from "sanitize-html";
|
|
|
|
// The real guard for landing-page rich text (add-landing-pages design decision 8): an allow-list of what the editor
|
|
// produces, applied on the server render. Saves also refuse scripts, but rows written another way still pass here.
|
|
// Ported from babyboo's richText.ts, minus images, tables, iframes and colours.
|
|
const OPTIONS: sanitizeHtml.IOptions = {
|
|
allowedTags: ["p", "h2", "h3", "strong", "em", "u", "s", "blockquote", "hr", "br", "ul", "ol", "li", "a"],
|
|
allowedAttributes: { a: ["href", "target", "rel"], p: ["style"], h2: ["style"], h3: ["style"] },
|
|
allowedStyles: { "*": { "text-align": [/^(left|center|right)$/] } },
|
|
allowedSchemes: ["https", "mailto", "tel"],
|
|
allowProtocolRelative: false,
|
|
transformTags: {
|
|
a: (tagName, attribs): sanitizeHtml.Tag => {
|
|
const href = attribs.href ?? "";
|
|
const out: sanitizeHtml.Attributes = href ? { href } : {};
|
|
if (/^https:/i.test(href)) Object.assign(out, { target: "_blank", rel: "noopener noreferrer nofollow" });
|
|
return { tagName, attribs: out };
|
|
},
|
|
},
|
|
};
|
|
|
|
export function sanitizePageHtml(html: string): string {
|
|
return sanitizeHtml(html, OPTIONS);
|
|
}
|