JSFiddle - React, Tailwind, and code Playground
by harperj1029
JavaScript
/*var input ='<br><P style="MARGIN: 0in 0in 10pt"><br/>First sgement </p><br /><p>my paragraph.</p> Some { and } characters characters too (ooh!) </p><B><SPAN style="COLOR: red"><span class="blah">This is < bold > and red</SPAN></B></P> oo and More > stuff < yay! <u><i>yummy text decoration</i></u></span>';*/
var input ='<h1 style="margin: 24pt 0in 0pt"><font color="#365f91" face="Cambria" size="5">Testing formatted text</font></h1><p class="MsoNormal" style="margin: 0in 0in 10pt"><i style="mso-bidi-font-style: normal"><font face="Calibri">This paragraph is italic<o:p></o:p></font></i></p><p class="MsoNormal" style="margin: 0in 0in 10pt"><span style="text-decoration: underline"><font face="Calibri">This is underline<o:p></o:p></font></span></p><p class="MsoNormal" style="margin: 0in 0in 10pt"><b style="mso-bidi-font-weight: normal"><font face="Calibri">This is bold<o:p></o:p></font></b></p><p class="MsoNormal" style="margin: 0in 0in 10pt"><b style="mso-bidi-font-weight: normal"><span style="color: red"><font face="Calibri">This is bold and red<o:p></o:p></font></span></b></p><p class="MsoNormal" style="margin: 0in 0in 10pt"><span style="font-family:">This is a different font<o:p></o:p></span></p>';
//console.log(input)
function tokenize(str, group1) {
return '[' + group1 + ']';
}
function unTokenize(str, group1) {
var selfCloseSlash=(group1.toLowerCase()=="br")?"/":"";
return '<' + group1 + selfCloseSlash+ '>';
}
input= input.replace(/<(br{1}|\/?[piub]{1}).*?>/gim,tokenize);
input = input.replace(/(\s{1}<\s{1})/gim,'[[');
input = input.replace(/(\s{1}>\s{1})/gim,']]');
input = input.replace(/<.[^>]*>/gim,'');
input = input.replace(/\[(br\s?\/?|\/?[piub]{1})\s?\/?\]/gim,unTokenize);
input = input.replace(/\[\[/gim,' < ');
input = input.replace(/\]\]/gim,' > ');
console.log(input);