Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

fix(posts): turn unsupported block tags into paragraphs when sanitizing content

Gilad Resisi14e5a4679558
diff --git a/libraries/helpers/src/utils/sanitize.post.content.ts b/libraries/helpers/src/utils/sanitize.post.content.ts
index 7be30dabc..cd298bab8 100644
--- a/libraries/helpers/src/utils/sanitize.post.content.ts
+++ b/libraries/helpers/src/utils/sanitize.post.content.ts
@@ -44,7 +44,14 @@ export const sanitizePostContent = (value: unknown): string => {
return '';
}
- return DOMPurify.sanitize(value, {
+ // a block tag the editor doesn't know would be dropped with its text kept,
+ // gluing its line to the next one
+ const paragraphs = value.replace(
+ /<(\/?)(div|section|article|blockquote|pre|h[4-6])\b[^>]*>/gi,
+ '<$1p>'
+ );
+
+ return DOMPurify.sanitize(paragraphs, {
ALLOWED_TAGS,
ALLOWED_ATTR,
ALLOWED_URI_REGEXP: /^(?:https?:|mailto:|\/|#)/i,