Javascript: Include empty lines when splitting strings
<p>Edit: This is the code where I will apply the split:</p>

<p>A have a code snippet surrounded inside pre tags</p>

<pre><code>&lt;pre class="codeSample"&gt;
public class Foo 
{
}

public class Bar
{
}
&lt;/pre&gt;
</code></pre>

<p>and here is my jquery code:</p>

<pre><code>var content = $('.codeSample').html();
$('codeSample').html('');  //Clear to ready for new output
var preTag = $('.codeSample');
var lines = content.split('\n');

for(i=0;i&lt;lines.length;i++)
   preTag.append('&lt;div&gt;' + lines[i] + '&lt;/div&gt;');
</code></pre>

<p>The output is this when rendered by the browser:</p>

<pre><code>public class Foo 
{
}
public class Bar
{
}
</code></pre>

<p>The extra empty line between the two classes is gone.</p>

<p>Edit:</p>

<p>Right now, the following is my solution to fix this:</p>

<pre><code>var content = $('.codeSample').html().replace(/\n(?=\n)/g, '\n ');
</code></pre>

<p>This code looks for two consecutive \n and inserts a blank space between them. Now when I do the split, empty lines are included in the array result but they contain a blank space in them. Any alternatives? Thanks.</p>

<p>Edit:</p>

<p>Okay, I will just consider my own solution. Thanks for the replies.</p>
