JSFiddle - React, Tailwind, and code Playground
by rgthree
HTML
<h2>Original:</h2>
<pre id="one"></pre>
<br /><br />
<h2>Stripped:</h2>
<pre id="two"></pre>
CSS
h2 {margin-bottom:5px; text-decoration:underline;}
JavaScript
var str = "This is an oddly\nbroken paragraph that\nwill turn into one string.\n\nThis is still a new\nand separate paragraph that\nis also not broken.";
document.getElementById('one').innerHTML = str;
// Replace All newlines not followed by one with a space.
// Then replace all newlines left with another.
document.getElementById('two').innerHTML = str.replace(/\n(?!\n)/g, ' ').replace(/\n+\s/g, '\n\n');