Skip to content

Commit 4a4a14e

Browse files
author
Simon Bjerre
committed
sanitizeHtml
1 parent 97272fd commit 4a4a14e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/components/Announcements.tsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ async function AnnoucementPosts() {
4141
}
4242
var data = await AnnoucementPosts()
4343

44+
const sanitizeHtml = (html: any) => {
45+
const parser = new DOMParser();
46+
const doc = parser.parseFromString(html, "text/html");
47+
48+
// Remove all <img> tags
49+
const images = doc.querySelectorAll("img");
50+
images.forEach((img) => img.remove());
51+
52+
return doc.body.innerHTML;
53+
};
54+
4455
const Annoucements = () => {
4556

4657
return (
@@ -53,7 +64,7 @@ const Annoucements = () => {
5364
<div className="font-semibold text-lg md:text-xl text-secondary dark:text-white">
5465
{post.title}
5566
</div>
56-
<div className="text-sm line-clamp-2" dangerouslySetInnerHTML={{__html: post.content}}>
67+
<div className="text-sm line-clamp-2" dangerouslySetInnerHTML={{__html: sanitizeHtml(post.content)}}>
5768

5869
</div>
5970
</div>

0 commit comments

Comments
 (0)