2023-03-28 09:40:13 +00:00
|
|
|
import sanitizeHtml from "sanitize-html";
|
|
|
|
|
|
|
|
import { md } from "@calcom/lib/markdownIt";
|
|
|
|
|
2023-08-16 18:03:21 +00:00
|
|
|
if (typeof window !== "undefined") {
|
|
|
|
// This file imports markdown parser which is a costly dependency, so we want to make sure it's not imported on the client side.
|
|
|
|
// It is still imported at some places on client in non-booker pages, we can gradually remove it from there and then convert it into an error
|
|
|
|
console.warn("`markdownToSafeHTML` should not be imported on the client side.");
|
|
|
|
}
|
|
|
|
|
2023-03-28 09:40:13 +00:00
|
|
|
export function markdownToSafeHTML(markdown: string | null) {
|
2023-06-09 12:50:35 +00:00
|
|
|
if (!markdown) return "";
|
2023-03-28 09:40:13 +00:00
|
|
|
|
|
|
|
const html = md.render(markdown);
|
|
|
|
|
|
|
|
const safeHTML = sanitizeHtml(html);
|
|
|
|
|
|
|
|
const safeHTMLWithListFormatting = safeHTML
|
|
|
|
.replace(
|
|
|
|
/<ul>/g,
|
|
|
|
"<ul style='list-style-type: disc; list-style-position: inside; margin-left: 12px; margin-bottom: 4px'>"
|
|
|
|
)
|
|
|
|
.replace(
|
|
|
|
/<ol>/g,
|
|
|
|
"<ol style='list-style-type: decimal; list-style-position: inside; margin-left: 12px; margin-bottom: 4px'>"
|
2023-07-21 18:00:28 +00:00
|
|
|
)
|
|
|
|
.replace(/<a\s+href=/g, "<a target='_blank' class='text-blue-500 hover:text-blue-600' href=");
|
2023-03-28 09:40:13 +00:00
|
|
|
|
|
|
|
return safeHTMLWithListFormatting;
|
|
|
|
}
|