I've just posted an answer that involved some HTML, which I indented by four spaces.


compare to the original input I made:


It seems as though &nbsp; gets replaced by an actual non-breaking space within a code section in the final output. I think this was not always the case (can someone confirm?), and it generally contradicts the meaning of a code section.

This is also inconsistent with the way text within backticks is treated. Now I know I could circumvent that by using &amp;nbsp;, but I'm very hesitant of this double encoding of source code.

Is it a bug?

  • 10
    Better use &amp;amp;nbsp; to be double-super safe... – Hilarious Comedy Pesto Jul 7 '09 at 18:14
  • 3
    @Pesto: This was not helpful. At all. – Tomalak Jul 7 '09 at 18:18
  • 6
    He wasn't trying to be – jjnguy Jul 7 '09 at 20:34
  • 2
    Refresh this page, and watch the first code block in the question: you can see the &nbsp; get changed to a space! – Blorgbeard is out Jul 8 '09 at 5:14
  • @Blorgbeard: Definitely a client-side bug. Strange but I've missed this glitch so far. Chances are that this will never be fixed since it would instantly invalidate all those "work-arounded" code samples. – Tomalak Jul 8 '09 at 7:10

This appears fixed, at least to me, in the later prettify.js we've deployed.


If you check the source of the page, the &nbsp; is written as &amp;nbsp;, so the double-decoding is happening on the client, not the server. That's pretty interesting.

It's a bug in the code formatter itself. Isn't that a component written externally to SO?

  • 2
    google prettify code.google.com/p/google-code-prettify – Jeff Atwood Jul 7 '09 at 18:26
  • 2
    @Jeff @wood: Time to submit an issue to Google. – Welbog Jul 7 '09 at 18:30
  • 3
    @Jeff: Are you trying to suggest Google did something wrong?! – Hilarious Comedy Pesto Jul 7 '09 at 18:31
  • 1
    @Pesto: I told you he was a MS fanboi apologist! – GEOCHET Jul 7 '09 at 18:31
  • 1
    @Jef fAtwood: You should fork prettify and give Spolsky a heart attack. – GEOCHET Jul 7 '09 at 18:38
  • 1
    So if I had to guess then I'd say that this is one of the bugs that can never be fixed because there is an unknown number of code samples that are built around it. They would instantly become invalid. – Tomalak Jul 8 '09 at 7:13
  • @Tomalak ​ It only means that people will have to edit them, when the find them. – Brad Gilbert Aug 14 '09 at 15:19
  • @Brad Gilbert: You could look at it that way, yes. But it also means that code will be subtly wrong for J. Random Coder, who finds the page through Google. Which is sub-optimal. – Tomalak Aug 25 '09 at 13:38

It is a bug, as shown by this example:


The first is &nbsp; and the second is &amp;nbsp;. (I've used an extra level of entification to type the preceding sentence, and hope that it still comes out right when I post it.) Really nasty is that the preview initially shows the code as typed, but then replaces it with a space when it syntax-colours it after some random interval.

The bug does seem to be peculiar to nbsp. I haven't found any other character code that does it.


here is an example of the bug:

using a html entity in xslt (e.g. &nbsp;)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .