JSFiddle - React, Tailwind, and code Playground
HTML
<div id="content">
<button>Replace double breaks with paragraphs</button>
<p>
"Paragraph 1" <br />
<a href="http://xkcd.com/246/">Link, the first</a>
Line after single break.
<u><br /></u>
"Paragraph 2"
<br /><br />
"Paragraph 3"
<em><a href="http://xkcd.com/262/">Nested Link</a></em>
<br /><br />
</p>
<p>
<br/>Title:<u> </u></p>
<table border="0" style="width: 624.4px;" data-line-id="eaed80e5-5c40-ab86-92aa-741081679573"><tbody><tr data-line-id="8c3826b0-80a6-453a-45cc-2c9ac37c3e75"><td data-line-id="40f6e96b-600c-d5ec-062e-3ec7a1cd9699"><p class="" data-line-id="3c9d5807-ac37-492f-13b4-d568ae7c8b8d"><strong>Discloser</strong></p></td><td data-line-id="5de8c6d3-dc20-0447-d4d5-c732ed1c2521"><p class="" data-line-id="70270693-8377-ac66-0ff5-946299ff68a3" data-left-indent="0.1125" style="margin-left: 10.8px;"><strong>Recipient</strong></p></td></tr><tr data-line-id="b78742fd-7d78-d08b-7efa-075cf0f11d81"><td data-line-id="b9763f95-66a8-6c9b-5352-e0c53e5fdf3e"><p class="" data-line-id="1e8ef55e-3f06-d17a-b8d0-0ebc6e6d47b9">By: <u><br></u></p><p class="" data-line-id="69bdb3f4-1aa5-7f27-18e6-04cfdb6918bb"><u><br></u>______________________________<u><br></u>Perry Ziff<br></p></td><td data-line-id="11ce4a46-41c3-0841-25aa-ed9aaa9057cd"><p class="" data-line-id="f42bad9e-344f-653a-34d7-a7801db46db2" data-left-indent="0.1125" style="margin-left: 10.8px;">By: <u> <br></u></p><p class="" data-line-id="db6c9a35-a787-7be9-b2fc-3ab95df751b7" data-left-indent="0.1125" style="margin-left: 10.8px;"><u><br></u>Name: ______________________________<br></p><p class="" data-line-id="c58b7312-b6e5-4439-cb40-8d6777d7d28b" data-left-indent="0.1125" style="margin-left: 10.8px;"><br>Title:<u> </u></p></td></tr></tbody></table>
</div>
JavaScript
$("button").click ( function () {
var badGraphs = $("#content p:has(br)");
var targetP = null;
var justSplit = false;
badGraphs.each ( function () {
var parentP = $(this);
parentP.contents ().each ( function (J) {
if (justSplit) {
justSplit = false;
return true; // "continue" the loop.
}
var thisjNode = $(this);
var nextjNode = $(this.nextSibling);
if (thisjNode.is ("br") && nextjNode.length > 0 ) {
thisjNode.remove (); //-- Kill this <br>
//nextjNode.remove (); //-- and the next
//-- Create a new p for any following content
targetP = targetP || parentP;
targetP.after ('<p></p>');
targetP = targetP.next ("p");
justSplit = true;
}
else if (targetP) {
targetP.append (this);
console.log ("Moving: ", this);
}
} );
} );
} );