9

I'm trying to write a single backslash in a comment as code formatted by backtick. Like this:

`\`

but it escapes the backtick and doesn't close the "inline code block".

I've read Backslash escaped with backticks rendered incorrectly in comments but couldn't figure out.

How do I format a single backslash in comment as code?

  • Seems like the answer is to add a trailing space, or just don't do use code (I question whether it really needs to be formatted differently). It's one of the markdown edge cases where it can't decide whether \ is code or an escape character. – Aaron Bertrand Oct 14 '13 at 15:48
8

Using 2 backticks seems to work

``\``

BTW if you want to escape a backtick use

`\``
  • escaped backshlash \ and escaped backtick ` – juergen d Oct 14 '13 at 15:57
  • 1
    Let's \ try it. edit wow! it works! :D – n611x007 Oct 14 '13 at 15:59
  • 5
    ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​​ ​ ​ ​ ​ ​ ​ ​ – Amal Murali Oct 14 '13 at 16:18
6

``\``\ : to format a single backslash as `code` in comments, enclose it in double backticks.

Same for the more general case of a \ at the end of a `code` section:
Comment source ``C:\Windows\`` renders to C:\Windows\.

A backslash at any position other than the end works fine between `single backticks`. (As well as ``double ones``.)

(\ is not treated as special in comment `code` sections, except when followed by a backtick while enclosed by single backticks:
Comment source `…\`…` renders to …`….
But ``…\`…`` renders to …\`….

If you need both a trailing backslash \ and any number of backticks ` at the beginning, you can go dirty hack and separate the content backticks from the surrounding backticks with an invisible Unicode character, like zero width space: You can copy it from between the arrows: →​← (It's invisible, but it's there, I promise! ;) To get a hold of it, copy the arrows along with it, then delete them after pasting.)

(If you need both a trailing backslash \ and an occurrence of a double backtick `` in the interior of your `code` section, you can enclose it in triple backticks ```…``` and so on.)
)

Credits: This post was helped by juergen d's answer and ThisSuitIsBlackNot's comment (on a similar question) - thanks!

You must log in to answer this question.

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