* 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>
22 lines
571 B
TypeScript
22 lines
571 B
TypeScript
import DOMPurify from "dompurify";
|
|
|
|
import { md } from "./markdownIt";
|
|
|
|
export function markdownAndSanitize(markdown: string | null) {
|
|
if (!markdown) return "";
|
|
|
|
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 = DOMPurify.sanitize(html);
|
|
return safeHtml;
|
|
}
|