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.
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.
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?
What I got right now is:
var content = $this.html()
.replace(/\t\t\t\t\t\t/g, " ")
.replace(/\t\t\t\t\t/g, " ")
.replace(/\t\t\t\t/g, " ")
.replace(/\t\t\t/g, " ")
.replace(/\t\t/g, " ")
.replace(/\t/g, "");
$this.html(content);
I think you should use a jQuery syntax highlighter and let the plugin do the work for you.
http://alexgorbatchev.com/SyntaxHighlighter/
http://steamdev.com/snippet/