Fixes formatted description in email (#7696)

* 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 <[email protected]>
Co-authored-by: Hariom Balhara <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
authored and GitHub committed 2023-03-23 12:00:42 +00:00
1 parent 520e7fe036
commit f6d7568d0a
23 files changed
+699 -379

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
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;
}
@@ -0,0 +1,21 @@
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;
}
-9
View File
@@ -1,12 +1,3 @@
import MarkdownIt from "markdown-it";
export const md = new MarkdownIt("default", { html: true, breaks: true, linkify: true });
export function addListFormatting(html: string) {
return html
.replaceAll("<ul>", "<ul style='list-style-type: disc; list-style-position: inside; margin-left: 12px'>")
.replaceAll(
"<ol>",
"<ol style='list-style-type: decimal; list-style-position: inside; margin-left: 12px'>"
);
}