Replace all newlines except para breaks

by adamh

HTML

<h1>Instructions for removing line breaks from PDF text</h1>
<div>
    <ol>
        <li>Paste from pdf into box</li>
        <li>Put a line between paragraphs</li>
        <li>Press <code>convert</code></li>
        <li>Copy + paste the result into CMS</li>
    </ol>
</div>
<form>
    <textarea></textarea>
    <button>Convert &raquo;</button>
</form>

CSS

body {
    padding: 10px;
    font-family: Helvetica, Arial, sans-serif;
    font-size: 12px;
    line-height: 1.4em;
}

h1 {
    font-size: 14px;
}

div {
    float: left;
    width: 40%;
    box-sizing: border-box;
    padding: 10px;
}

form {
    float: right;
    width: 60%;
    box-sizing: border-box;
    padding: 10px;
}

textarea {
    box-sizing: border-box;
    border: 1px solid #57676e;
    border-radius: 2px;
    width: 100%;
    height: 400px;
}

JavaScript

jQuery.fn.cleanWhitespace = function() {
    newVal = this.val().replace(/\n\n/g, "{double}");
    newVal = newVal.replace(/\n/g, " ");
    newVal = newVal.replace(/{double}/g, "\n\n");
    //newVal = this.val().replace("^\\s+|\\s+$|\\s*(\n)\\s*|(\\s)\\s*", "$1$2").replace("\t"," ");
    this.val(newVal);
}
$('button').click(function(ev){
    ev.preventDefault();
    ev.stopPropagation();
    $('textarea').cleanWhitespace();
});