* fix description in email * add styling for lists * sanitize editor input before saving * sanitize eventTypeDescription * santize html when used dangerouslySetInnerHTML * fix server side sanitation * add missing formatting and sanitation * move @ts-expect-error to correct line * fix type error and add yarn.lock * fix build error * sanitize description for booking page and availability page * rename to markdownAndSanitize * always add list formatting * handle empty description in markdownAndSanitize for cleaner code * create function for clientside markdown rendering and sanitizing * fix type error * code clean up * Now that eventType.descriptionAsSafeHTML is added at all the missing places, we can do away with ts-ignore and get type safety * Remove unused variable * Remove one more ts-expect-error --------- Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com>
26 lines
797 B
TypeScript
26 lines
797 B
TypeScript
import DOMPurify from "dompurify";
|
|
import { JSDOM } from "jsdom";
|
|
|
|
import { md } from "@calcom/lib/markdownIt";
|
|
|
|
export function markdownAndSanitize(markdown: string | null) {
|
|
if (!markdown) return null;
|
|
|
|
const window = new JSDOM("").window;
|
|
// @ts-expect-error as suggested here: https://github.com/cure53/DOMPurify/issues/437#issuecomment-632021941
|
|
const purify = DOMPurify(window);
|
|
|
|
const html = md
|
|
.render(markdown)
|
|
.replaceAll(
|
|
"<ul>",
|
|
"<ul style='list-style-type: disc; list-style-position: inside; margin-left: 12px; margin-bottom: 4px'>"
|
|
)
|
|
.replaceAll(
|
|
"<ol>",
|
|
"<ol style='list-style-type: decimal; list-style-position: inside; margin-left: 12px; margin-bottom: 4px'>"
|
|
);
|
|
const safeHtml = purify.sanitize(html);
|
|
return safeHtml;
|
|
}
|