Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 157 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

I recently noticed that comments don't highlight spaces over newlines in code blocks.

For example, I posted a comment containing ", ".join(), and then, when displayed, it looked like this:

Screenshot of missing space.

As you can see, the space is not highlighted correctly - when copy/pasted, the space is there, but this does change how it looks.

Not a vital thing, but thought it was worth a mention.

share|improve this question
up vote 5 down vote accepted

This isn't a problem with Stack Overflow. Code highlighted using the <code> HTML tag, which is an inline-level element. This means that it will line-wrap when possible (Spaces are those "seams" where a line-wrap can occur).

There's nothing much to be done, and frankly, I don't think that anything should be done. It's quite an edge case. Just edit your comment a little bit and it'll display fine.

share|improve this answer
I'm familiar with the reason for this - that doesn't mean there is no work-around to have it display correctly (even something as simple as converting spaces into non-breaking spaces, for example - although that could cause larger layout issues). This said it is obviously, as you say, a pretty small bug so it wouldn't necessarily be worthwhile. – Latty Feb 25 '13 at 21:08
If you convert spaces into NBSPs, copy-pasting the code will fail on any compiler. Hene, the solution isn't viable. – Madara Uchiha Feb 25 '13 at 21:13
That's very true - it was also a bad idea for other reasons - I was just making the point there is the potential for a fix here, just because this is the way HTML works, doesn't mean that there is nothing that can be done to make it more suitable for this need. – Latty Feb 25 '13 at 21:15

The only thing I can think of that would fix this is replacing spaces with &nbsp; (non-breaking spaces), which would cause the entire thing to stay together and thus keep the space visible. However, longer blocks of code then would never break and would extend past the screen, because there are never any breaking points in it.

An alternate way is to add &nbsp; before the actual space, without removing the space itself, which would show the physical space there while still wrapping on the regular space. It would be visually pleasing, but copying and pasting the code like that would render two spaces in the text.

Browsers wrap spaces like that, it's how they're designed. So, there's really nothing we can do about it without an extraordinary amount of work, and that amount of work just isn't feasible for something as minor as this.

share|improve this answer
Like I said in a comment on my answer. If you use an &nbsp; instead of spaces, the code becomes uncopypastable. It won't compile or work anymore. – Madara Uchiha Feb 25 '13 at 21:21

You must log in to answer this question.

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