Reference: just looking at the accepted answer (over the course of a year or so :)) helped me figure the below pattern out:
Summary of the backtick pattern for inserting backticks into markdown in or not in code blocks
1. In single-line code blocks
Use a double backtick (``) at the start and end of a code block to allow a single backtick within it:
`` ` ``
produces: `
Use a triple backtick (```) at the start and end of a code block to allow a double backtick within it:
``` `` ```
produces: ``
Use a quadruple backtick (````) at the start and end of a code block to allow a triple backtick within it:
```` ``` ````
produces: ```
Use a quintuple backtick (`````) at the start and end of a code block to allow a quadruple backtick within it:
````` ```` `````
produces: ````
Etc.
2. Within multi-line code blocks (between code fences)
A normal multi-line code block begins with a code fence which uses 3 backticks:
``` <-- starting code fence
code goes here
``` <-- ending code fence
So this C code block:
```c
void main(int argc, char* argv[])
{
// your code goes here
return 0;
}
```
produces this:
void main(int argc, char* argv[])
{
// your code goes here
return 0;
}
But, it turns out you can have code fences within your code blocks so long as your outer code blocks use code fences with more backticks, same as we saw previously in the single-line code block examples above.
So this:
````
```c
// some comment
```
````
produces this:
```c
// some comment
```
And this:
`````c
````
```
// some comment
```
````
`````
produces this:
````
```
// some comment
```
````
3. Not in code blocks (use a backslash before each backtick)
To insert backticks into markdown not formatted as code blocks, just use a backslash in front of the backticks.
Ex:
- This:
\`\`\`
produces this: ```
- And the way I even type up this:
\`\`\`
is like this: `` \`\`\` ``
. (Now guess how I even typed up that into this markdown answer!--3 backticks added to the beginning and end of that, of course! )
Going further
To add clarity to the accepted answer, here is an example:
To produce this, which has a single backtick near the end, but in code format:
syntax error near unexpected token `|'
Do this. Notice the double-backtick (``) at the beginning and end, in order to allow a single backtick (`) anywhere in between the two:
``syntax error near unexpected token `|'``
...which produces this: syntax error near unexpected token `|'
, which is what I want!
This is from my question here where I was trying to quote a bash error: Bash: how to print and run a cmd array which has the pipe operator, |, in it