Files
co-lite/solvway-admin-portal/app/lib/pageHtml.ts
T
ngqileandClaude Opus 5.5 bb2c5c5db7 feat(portal): landing pages list, editor, preview and public page
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
2026-12-02 16:30:54 +08:00

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);
}