How is Stackoverflow removing and adding &nbsp; to their { code }?
<p>I'm having some fun with, copy/pasting code into textarea and then trying to make it look decent in a "pre" "/pre"... And of course I've looked at SO.</p>

<p>But I'm having some troubles with to much whitespace, so I'm trying to replace \t with some nbsp; but it's not getting.. like really pretty. </p>

<p>So I was wondering, how would be a nice way of doing this? How is SO doing it? Is it even able to do it in a decent way?</p>

<p>What I got right now is:</p>

<pre><code>var content = $this.html()
                        .replace(/\t\t\t\t\t\t/g, "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;")
                        .replace(/\t\t\t\t\t/g, "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;")
                        .replace(/\t\t\t\t/g, "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;")
                        .replace(/\t\t\t/g, "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;")
                        .replace(/\t\t/g, "&amp;nbsp;&amp;nbsp;&amp;nbsp;")
                        .replace(/\t/g, "");
        $this.html(content);
</code></pre>
