Skip to content

Scheduling infrastructure for absolutely everyone.

fix(ui): render markdown headings properly in event descriptions (#29648)

Gaurav Kumar032962f5775d
diff --git a/packages/lib/markdownToSafeHTML.ts b/packages/lib/markdownToSafeHTML.ts
index b805b1a3355..e6de95bd7ac 100644
--- a/packages/lib/markdownToSafeHTML.ts
+++ b/packages/lib/markdownToSafeHTML.ts
@@ -1,6 +1,5 @@
-import sanitizeHtml from "sanitize-html";
-
import { md } from "@calcom/lib/markdownIt";
+import sanitizeHtml from "sanitize-html";
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.
@@ -24,7 +23,9 @@ export function markdownToSafeHTML(markdown: string | null) {
/<ol>/g,
"<ol style='list-style-type: decimal; list-style-position: inside; margin-left: 12px; margin-bottom: 4px'>"
)
- .replace(/<a\s+href=/g, "<a target='_blank' class='text-blue-500 hover:text-blue-600' href=");
+ .replace(/<a\s+href=/g, "<a target='_blank' class='text-blue-500 hover:text-blue-600' href=")
+ .replace(/<h1[^>]*>/g, "<h1 style='font-size: 25px; font-weight: bold; margin-bottom: 8px'>")
+ .replace(/<h2[^>]*>/g, "<h2 style='font-size: 20px; font-weight: bold; margin-bottom: 8px'>");
// Match: <li>Some text </li><li><ul>...</ul></li>
// Convert to: <li>Some text <ul>...</ul></li>
@@ -34,4 +35,4 @@ export function markdownToSafeHTML(markdown: string | null) {
);
return safeHTMLWithListFormatting;
-}
+}
\ No newline at end of file
diff --git a/packages/lib/markdownToSafeHTMLClient.ts b/packages/lib/markdownToSafeHTMLClient.ts
index 434f4aa9c84..4e35f5467b1 100644
--- a/packages/lib/markdownToSafeHTMLClient.ts
+++ b/packages/lib/markdownToSafeHTMLClient.ts
@@ -1,6 +1,5 @@
-import DOMPurify from "dompurify";
-
import { md } from "@calcom/lib/markdownIt";
+import DOMPurify from "dompurify";
if (typeof window == "undefined") {
console.warn(
@@ -24,7 +23,9 @@ export function markdownToSafeHTMLClient(markdown: string | null) {
/<ol>/g,
"<ol style='list-style-type: decimal; list-style-position: inside; margin-left: 12px; margin-bottom: 4px'>"
)
- .replace(/<a\s+href=/g, "<a target='_blank' class='text-blue-500 hover:text-blue-600' href=");
+ .replace(/<a\s+href=/g, "<a target='_blank' class='text-blue-500 hover:text-blue-600' href=")
+ .replace(/<h1[^>]*>/g, "<h1 style='font-size: 25px; font-weight: bold; margin-bottom: 8px'>")
+ .replace(/<h2[^>]*>/g, "<h2 style='font-size: 20px; font-weight: bold; margin-bottom: 8px'>");
// Match: <li>Some text </li><li><ul>...</ul></li> or
// Convert to: <li>Some text <ul>...</ul></li>