Sanitizing HTML is going to be very difficult. If you just want text styling, then I will suggest your native storage format be Markdown, and you use a markdown to HTML formatter that you can control. For example, if you do not want to allow URL links, you can tell the formatter to treat those as plain text instead. Things like that. Since you control the HTML creation, your ability to sanitize it is greatly improved and possibly unnecessary. Still, when using the HTML you can use a library like DOMPurifyDOMPurify to try and prevent HTML injection attacks.
Since you tagged edge functions, I see you are using javascript. I use the markedmarked library for converting markdown to HTML. Also,I use MDXeditorMDXeditor for user input of markdown (it has many switches to limit what the user can do) in my app. There is no shortage of options here if you don't like these ones.