escapingmarkdownblock

How to include a backtick in inline code in Markdown with no space at the end


I would like to have the following code block:

i`

Become an inline code with no spaces at the end

So for example, I can do this and it will work:

``i` ``

It produces:

i`

However, there is a character at the end of that last example. Is it possible to produce an inline code snippet without that extra space character?

If we try the following:

``i```

It produces:

``i```

I am curious if I did something wrong or this is a limitation with Markdown. i.e. it is not possible to do.


Solution

  • The trick is to also start with a space. This:

    `` i` ``
    

    renders as:

    i`

    From the CommonMark spec:

    If the resulting string both begins and ends with a space character, but does not consist entirely of space characters, a single space character is removed from the front and back. This allows you to include code that begins or ends with backtick characters, which must be separated by whitespace from the opening or closing backtick strings.