JQuery - How to convert html with br's in it to html with p's in it?
<p>On the my page I have html like this:</p>

<pre><code>hi&lt;br&gt;bye&lt;br&gt;sigh&lt;br&gt;hello &lt;em&gt;tie&lt;/em&gt;&lt;br&gt;lie 
</code></pre>

<p>with jquery, how can I convert it to html like this (basically using p's instead of br's):</p>

<pre><code>&lt;p&gt;hi&lt;/p&gt;&lt;p&gt;bye&lt;/p&gt;&lt;p&gt;sigh&lt;/p&gt;&lt;p&gt;hello &lt;em&gt;tie&lt;/em&gt;&lt;/p&gt;&lt;p&gt;lie&lt;/p&gt; 
</code></pre>

<p>My first attempt at doing this was this code:</p>

<pre><code>$(container).contents().filter(function() {
                var val = this.nodeValue;
                return this.nodeType == TEXT_NODE &amp;&amp; $.trim(val).length &gt; 0;
            })
            .wrap('&lt;p&gt;&lt;/p&gt;')
            .end()
            .filter('br')
            .remove();
</code></pre>

<p>This worked for the most part, except that <code>hello</code> and <code>&lt;em&gt;tie&lt;/em&gt;</code> would not be in the same <code>p</code> element.</p>

<p>Does anyone know how I can do this properly?</p>
