Secure Markdown Rendering with DOMPurify and MarkdownIt

1 min read
0 Like
4 Views

Absolutely! Here's a sample markdown content that includes:

  • A heading
  • Bold and italic text
  • A link
  • A code block with potentially dangerous code (like a
    Plain Text
    ``

πŸ–ΌοΈ Example Image Tag (Should be escaped, not rendered)

HTML
<img src="https://evil.com/malicious.png">

πŸ“Œ Inline Code Example

Use the console.log("Hello World") command to debug your JavaScript.


Thanks for reading!
Stay safe πŸ‘¨β€πŸ’»πŸ‘©β€πŸ’»

Plain Text
You can copy this markdown and use your render function with MarkdownIt + DOMPurify like we discussed:

ts const safeHTML = DOMPurify.sanitize(md.render(markdownContent));

Plain Text
Let me know if you want this wrapped in a React component or Next.js preview page!
Share:

Comments

0

Join the conversation

Sign in to share your thoughts and connect with other readers

No comments yet

Be the first to share your thoughts!