DOm purify
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/0.8.2/purify.min.js"></script>
<p id="sanitized"></p>
JavaScript
'use strict';
var globalList = [];
// Specify dirty HTML
var dirty = "<!-- I am ready now, click one of the buttons! -->ac <script>in script<\/script> <b>hello</b>";
console.log("dirty => ",dirty);
dirty = dirty.replace(/(<!--)/g,'<comment>').replace(/(-->)/g,'</comment>');
console.log("dirty after custom tag => ",dirty);
// Clean HTML string and write into our DIV
var config = { ALLOWED_TAGS: ['b'],ADD_TAGS: ['comment']};
// Clean HTML string and write into our DIV
var clean = DOMPurify.sanitize(dirty, config);
console.log("clean before remove custom tag => ",clean);
clean = clean.replace(/(<comment>)/g,'<!--').replace(/(<\/comment>)/g,'-->');
console.log("clean => ",clean);