Created
July 14, 2021 00:45
-
-
Save ajinabraham/15e4a4b75bf48ed81c645da2fb682056 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- This example shows how to use simpleMDE safely with DOMPurify when dealing with intrusted user input. | |
Strip out javascript before rendering Markdown to HTML --> | |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css"> | |
<script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/2.1.3/marked.min.js" integrity="sha512-AD+GG1nJKO4Je/Q8QsY1gM9/7o1QjpGe9W2Lrg1oGtEID/RX8bMKKZGgw/KOODkPXL6j74c6eJWAhE/3F2kKjA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/2.3.0/purify.min.js" integrity="sha512-FJzrdtFBVzaaehq9mzbhljqwJ7+jE0GyTa8UBxZdMsMUjflR25f5lJSGD0lmQPHnhQfnctG0B1TNQsObwyJUzA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> | |
<textarea id="mde"></textarea> | |
<script> | |
var simplemde = new SimpleMDE({ | |
element: document.getElementById('mde'), | |
previewRender: function(plain) { | |
return DOMPurify.sanitize(marked(plain) , {USE_PROFILES: {html: true}} ); | |
}, | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment