JSFiddle - React, Tailwind, and code Playground

by Vladimir

HTML

<textarea></textarea>
<button>Clear</button>

CSS

textarea {
  width: 100%;
  height: 600px;
}

JavaScript

$(document).ready(function() {
	$('button').on('click',function() {
  	let txt = $('textarea').val();
    txt = txt.replace(/&nbsp;/g, ' ');
    txt = txt.replace(/\sdir="ltr"/g, '');
    txt = txt.replace(/\sstyle="[^"]+"/g, '');
    txt = txt.replace(/\sid="[^"]+"/g, '');
    txt = txt.replace(/\saria-level="[^"]+"/g, '');
    txt = txt.replace(/\srole="[^"]*"/g, '');
    txt = txt.replace(/\srel="[^"]*"/g, '');
    txt = txt.replace(/\stitle="[^"]*"/g, '');
    txt = txt.replace(/<\/?span>/g, '');
    txt = txt.replace(/<li>\s+<p>/g, '<li>');
    txt = txt.replace(/<\/p>\s+<\/li>/g, '</li>');
    txt = txt.replace(/\s+/g, ' ');
    txt = txt.replace(/<((p)|(li)|(ul)|(h1)|(h2))>\s*/g, '<$1>');
    txt = txt.replace(/<\/((p)|(li)|(ul)|(h1)|(h2))>\s*/g, '<\/$1>\n');
    $('textarea').val(txt);
  });
});