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 was answering a question on Stack Overflow and required to use a trailing space in one of my code snippets.

I formatted it like so:

`<a `

And it renders without the trailing space: <a

Using the <code> tag does account for trailing spaces, though in my case it busts because of the <. Here's my formatting with the <code> tag:

<code><a </code>

Here's how it renders: (Yes, you should see nothing there).

This is a pretty annoying bug. Can we get it fixed?

share|improve this question
    
Indent the line with 4 spaces. – Cody Gray Feb 27 '12 at 2:16
    
@CodyGray: What do you mean? – Mystery Feb 27 '12 at 2:20
    
Your original comment made more sense before it was edited: You want this to appear inline. – Cody Gray Feb 27 '12 at 7:14
    
@CodyGray: Well, then, I want it inline. :P – Mystery Feb 27 '12 at 7:14
up vote 5 down vote accepted

Is there some reason you can't just use the Unicode character U+00A0 (NO-BREAK SPACE) for that trailing space? It should work in comments too. To type the actual character on Windows, you can use the key combination ALT+0160.

Here's how it looks: <a 

share|improve this answer
    
Using Alt+0160 works. – Mystery Feb 27 '12 at 2:31
    
Good, I thought it shoudl. Of course, that’s only if you have your keyboard configured for Unicode input. I usually leave mine on the U.S. or U.S. International keyboard, and only switch to the Unicode input keyboard for entering a bunch of character by their code point number. Otherwise, I just use murine snarf-n-barf. – tchrist Feb 27 '12 at 2:33
    
Uh, I use the US keyboard layout, but Alt+0160 works just fine for me... – Cody Gray Feb 27 '12 at 7:13
    
@CodyGray You must be a prisoner of bill, then, right? – tchrist Feb 27 '12 at 11:45
    
Reference to Bill Gates? Not really. I'm actually a Mac user and have been for a long time. But I also do Windows programming, so yeah I use Windows for that. I've never used Alt+xxx keyboard shortcuts on the Mac, so I assumed you were talking about Windows. I guess they work in Ubuntu et al? – Cody Gray Feb 27 '12 at 17:06

Markdown strips leading and trailing whitespace in code spans:

http://code.google.com/p/pagedown/source/browse/Markdown.Converter.js#1011

http://code.google.com/p/markdownsharp/source/browse/MarkdownSharp/Markdown.cs#1358

The same is true for John Gruber's original Perl version. The comment before the function _DoCodeSpans also explains why:

#   *   You can use spaces to get literal backticks at the edges:
#     
#         ... type `` `bar` `` ...
#     

When you start a code span with, say, three backticks, you also have to end it with precisely three backticks. If the trailing whitespace was significant, it would be impossible to have a backtick at the end, since

```backtick: ````

is not a legal code span.

By the way, the reason that your <code><a </code> doesn't display anything is simple: It's broken HTML. You're opening an <a> tag, but you're not putting a closing angle bracket. So the sanitizer will remove the illegal HTML "tag" <a </code>, and then the tag balancer will remove the opening <code> tag, since it doesn't have a closing </code> anymore.

When you write your own HTML, Markdown won't do any encoding for you; you'l have to replace <a by &lt;a yourself:

foo <code>&lt;a </code> bar -> foo <a bar

foo <code>&lt;a&nbsp;</code> bar -> foo <a  bar

Between the last two, note the tiny difference in whitespace after the code, resulting from the browser's whitespace condensing.

share|improve this answer
    
Hmm, the fact that the original implementation uses [ \t]* seems inconsistent with the syntax guide's statement that "The backtick delimiters surrounding a code span may include spaces — one after the opening, one before the closing" (emphasis mine). Of course, even with the example in this question I still don't understand the use case that benefits from leaving extra spaces in, so the implementation makes more sense to me anyway. – Tim Stone Feb 27 '12 at 7:40
    
See this question for a use case of trailing spaces. – Andres Riofrio May 29 '12 at 5:09

You must log in to answer this question.

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