JSFiddle - React, Tailwind, and code Playground

HTML

<div id="container">
    <p>
     string
    <b>
      bold
        <em>italic string</em>
      also(bold)
    </b>
 </p>
</div>

JavaScript

var htmlstring = document.getElementById('container').innerHTML;
htmlstring = htmlstring.replace("<b>","</p><b>")
                        .replace("<em>","</b><em>")
                        .replace("</em>","</em><b>")
                        .replace("</b>","</c-b>")
                        .replace("</b>","</b><p>")
                        .replace("</c-b>","</b>");
console.log(htmlstring)