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

In questions/answers, to put backticks within my inline code I have to enclose the whole thing in double backticks.

``cd `brew --prefix` ``

In comments I can escape backticks with backslashes. I can't use backslashes like this in questions/answers. This seems like a better solution, but is obviously inconsistent.

`cd \`brew --prefix\``

Any good insight?

share|improve this question
    
Here's how these should really look when entering them, using the better comment-style escaping: ``cd `brew --prefix` `` (Q&A) and `cd \`brew --prefix\`` (comments) ... phew, that was a trip down the markdown wormhole! –  SWrobel Sep 23 '11 at 17:32

1 Answer 1

up vote 1 down vote accepted

If you're trying to do inline code like this you should probably not do that. The problem is that it's ambiguous — you can't tell whether the slash is supposed to be included in the code unless you force the use of \\ to produce a slash or something. No matter what you do, using surrounding characters will produce some sort of ambiguity like this. Should three backticks be rendered as one block with a backtick inside it, or a block with a backtick following it, or a block with a backtick preceding it? In this case the answer is none of the above: ```. There's no simple way to make all 4 versions possible.

The solution with the "unnecessary" space seems good to me, though — it's certainly not changing the meaning of your examples. But if needed, just don't use inline blocks.

Use a <pre> block like so:

` one backtick
` surrounded by one backtick `
`` two backticks
`` surrounded by two backticks ``
``` etc.
cd `brew --prefix`

Or simply indent by four spaces:

` one backtick
` surrounded by one backtick `
`` two backticks
`` surrounded by two backticks ``
``` etc.
cd `brew --prefix`
share|improve this answer
    
Yeah, but I want to do this inline! Thanks for the tip, though, I used it to format my question correctly since I couldn't get double backticks to escape inside inline code. –  SWrobel Sep 23 '11 at 17:36
    
@SWrobel I've added some more detail. For your examples using the extra space shouldn't harm anything, right? –  Matthew Read Sep 23 '11 at 17:46
    
Ok, thanks. I'm still curious why the markdown is different for comments and q/a though. It doesn't make sense. –  SWrobel Sep 23 '11 at 17:48
1  
@SWrobel Comments use a different restricted (mini) Markdown parser, which is why there's room for variation. This particular case seems like an issue with the normal Markdown parser though, but I'll need to check. –  Tim Stone Sep 23 '11 at 18:05
2  
@SWrobel Correction. The normal Markdown parser is doing things the expected way, and the backslash escape in comments was a workaround from before the correct syntax was supported in comments. I imagine the rationale for the correct syntax is pretty much what Matthew Read described above. –  Tim Stone Sep 23 '11 at 18:25
    
@TimStone thanks, that pretty much answers it! I didn't realize that you could go beyond 2 backticks without needing to escape within inline code. Now, I guess my question changes to why this isn't all spelled out in the markdown docs? –  SWrobel Sep 23 '11 at 19:24
    
@SWrobel: Because that's a level of detail that would probably be more confusing than helping. Note that our documentation links to the official markdown "spec", which does mention this. –  balpha Oct 7 '11 at 15:31

You must log in to answer this question.

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