What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 131 Stack Exchange communities.

Since I don't think we can use the <pre> tag, is there a way to preserve white space in comments? Backticks by themselves don't seem to do it:

Using backticks:
testing extra spaces

Using <code> tag:
testing extra spaces

Using <pre> tag:

testing     extra spaces

Using "Code Sample" toolbar button (Ctrl+K) (I guess this is the same as <pre><code>):

testing     extra spaces
share|improve this question
3  
Comments only have a few features because they are meant to be secondary to the answers, and not meant to contain important information. Can you give an example of, or explain why, comments need this feature? It may take quite a bit of convincing to get it accepted. –  Adam Davis Mar 17 '11 at 6:34
    
@Adam: This is the comment that prompted me to ask this question. It doesn't seem like enough to post a separate answer. I retagged this question to "support", since I don't really expect anything to be changed. I just wanted to know if there was a way. –  Cheran Shunmugavel Mar 17 '11 at 6:41
    
@Cheran: You can't use <code> in comments anyway, can you? Let me try: <code>testing extra spaces</code>. So no, not possible. What you can do in questions and answers: <code>testing &nbsp; extra spaces</code>. In comments there still might be a way with crazy unicode spaces. –  Hendrik Vogt Mar 17 '11 at 15:08
    
Agree; in passages surrounded by `, whitespace should be preserved. –  tenfour Mar 18 '11 at 1:53
1  
You use to be able to do the ol' backtick hackery trick: two spaces: ` ` ` ` -- but I think that broke a while ago. &nbsp; –  Earlz Mar 18 '11 at 2:11
1  
Hmm.. what about this? –  Shadow Wizard Mar 18 '11 at 10:11
    
@Shadow Wizard: how did you do that? When I type HTML entities, they just show up as plain text (i.e. &#160;) –  Cheran Shunmugavel Mar 18 '11 at 11:20
    
try this out....ah, okay, you're just typing in the actual non-breaking space character. I think that's a workable solution! Thanks! –  Cheran Shunmugavel Mar 18 '11 at 11:22
1  
@Cher doing it by holding ALT and pressing 255 in the keypad - the ♪♫ are there as well. ☻ –  Shadow Wizard Mar 18 '11 at 16:48

3 Answers 3

There's something odd about this.

When I leave the comment

this is a `code span with single space` a `code  span  with  double  space`

The rendered HTML is

<span class="comment-copy">
    this is a 
    <code>code span with single space</code> 
    a 
    <code>code  span  with  double  space</code>
</span>

So the whitespace is indeed correctly preserved in the source HTML

share|improve this answer
    
this is a code span with single space a code span with double space –  Jeff Atwood Mar 18 '11 at 7:25
    
I'm encouraged by reading that you find that odd, Jeff :-) –  Hendrik Vogt Mar 18 '11 at 7:48
    
@hendrik meh, I don't think <code> does anything except switch the font as balpha pointed out to me. –  Jeff Atwood Mar 18 '11 at 7:53
2  
Indeed, @Jeff: <code> should not render excessive whitespace. (That would then also include newlines et al. <code> is simply not <pre>.) –  Arjan Mar 18 '11 at 7:54
    
Thanks, that's really good to keep in mind. –  Hendrik Vogt Mar 18 '11 at 7:59
up vote 1 down vote accepted

Per @Shadow Wizard's comment, you can type a non-breaking space character by pressing ALT+255 on the keypad (or alternatively, ALT+0160). For example

`two  spaces`

is rendered as

<code>two&#160;&#160;spaces</code>

and the spaces are preserved.

EDIT: As Arjan pointed out, this should not be used when posting code, since someone could copy and paste it into their editor, and it possibly won't compile.

share|improve this answer
1  
...even if this is never removed, then the fragments are no longer true code. Copy & paste might then fail with odd compile messages? –  Arjan Mar 19 '11 at 10:11
    
@Arjan correct as usual, this should not be used to post code.. though never tried to compile code with those characters - anyone care to pick the glove? ;) –  Shadow Wizard Mar 19 '11 at 10:54
    
Good point, @Arjan. I hadn't thought about people copying and pasting. –  Cheran Shunmugavel Mar 19 '11 at 16:34

enter image description here

share|improve this answer
    
Nice, but that would also enable newlines. That has been declined for comments. –  Arjan Mar 19 '11 at 10:00

You must log in to answer this question.

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