Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render triple backticks as inline code block in Markdown?

I am writing a tutorial on GitHub about Markdown using Markdown and I want to write ``` but rendered as inline code block like this.

like image 712
Protonotarios Avatar asked Oct 19 '15 22:10

Protonotarios


1 Answers

The Syntax Rules are very clear about this:

To include a literal backtick character within a code span, you can use multiple backticks as the opening and closing delimiters:

``There is a literal backtick (`) here.``

which will produce this:

<p><code>There is a literal backtick (`) here.</code></p>

The backtick delimiters surrounding a code span may include spaces -- one after the opening, one before the closing. This allows you to place literal backtick characters at the beginning or end of a code span:

A single backtick in a code span: `` ` ``

A backtick-delimited string in a code span: `` `foo` ``

will produce:

<p>A single backtick in a code span: <code>`</code></p>

<p>A backtick-delimited string in a code span: <code>`foo`</code></p>

The one thing the rules don't mention, but works in the reference implementation is that the opening and closing backtick deliminators only need to be a different number of backticks than those in the code span. So if you what to have two or more consecutive backticks in a code span, then you can delimit with one backtick to open and one backtick to close the code span. The trick is using the spaces (as explained above) when the code span starts or ends with backticks.

In fact, many implementations get this right:

foo ` ``` ` bar

becomes

<p>foo <code>```</code> bar</p>

Apparently (as pointed out in a comment) a few implementations specifically require that the number of backticks in the deliminator be greater (not just different) than the number of backticks in the codespan. Putting that together with the whitespace rule, this should work on most implementations:

foo ```` ``` ```` bar

However, if neither method works with the Markdown implementation you are using, I would suggest filing a bug with the developers of that implementation. In the meantime, you can use raw HTML to force it to work:

foo <code>```</code> bar

becomes

<p>foo <code>```</code> bar</p>
like image 103
Waylan Avatar answered Oct 24 '22 15:10

Waylan