Skip to content

Commit

Permalink
sanitizeHtml
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Bjerre committed Jan 19, 2025
1 parent 97272fd commit 4a4a14e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/Announcements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ async function AnnoucementPosts() {
}
var data = await AnnoucementPosts()

const sanitizeHtml = (html: any) => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, "text/html");

// Remove all <img> tags
const images = doc.querySelectorAll("img");
images.forEach((img) => img.remove());

return doc.body.innerHTML;
};

const Annoucements = () => {

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

</div>
</div>
Expand Down

0 comments on commit 4a4a14e

Please sign in to comment.