user4385532
user4385532

Reputation:

How to put (in markdown) an inline code block that only contains a backtick character (`)

Use case: Describing a programming language that uses backticks for comments. What should I write?

Comments are entered with a whattoputhere character.

So I need an inline code block that only contains a backtick. How to enter this?

I read this question and its answers: How does one escape backticks in markdown?

But it doesn't seem to solve the problem. Apparently, to be able to put a single backtick in an inline code block I need to enclose it with doublebackticks, rather than single backticks, producing something like this:

``I can use a backtick ` here ``

I can use a backtick ` here

But in my use case this degeneraters to this:

`````

Which renders like this: `````

Is there any way to enter an inline code block that only contains a single backtick character in Markdown?

Upvotes: 53

Views: 20196

Answers (4)

JRichardsz
JRichardsz

Reputation: 16594

No one answer worked for me using github wiki.

The pre tag worked for me.

Input

enter image description here

Output

enter image description here

Real example

https://github.com/jrichardsz-software-architect-tools/t-rext/wiki/Complex-features

Upvotes: 0

Gabriel Staples
Gabriel Staples

Reputation: 53255

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

  1. Use a double backtick (``) at the start and end of a code block to allow a single backtick within it:

    `` ` `` produces: `

  2. Use a triple backtick (```) at the start and end of a code block to allow a double backtick within it:

    ``` `` ``` produces: ``

  3. Use a quadruple backtick (````) at the start and end of a code block to allow a triple backtick within it:

    ```` ``` ```` produces: ```

  4. Use a quintuple backtick (`````) at the start and end of a code block to allow a quadruple backtick within it:

    ````` ```` ````` produces: ````

  5. 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:

  1. This: \`\`\` produces this: ```
  2. 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

Upvotes: 56

pbarney
pbarney

Reputation: 2853

If you want to use backticks to surround a word that you do not want formatted as code (for example, `sql_columns`), there are three approaches that I'm aware of:

  1. Surround the word with the HTML entity code &#96; which will produce a backtick from StackOverflow's Markdown engine,
  2. Use the \&grave; HTML entity which produces `
  3. Use the \ as an escape for the backtick: typing \`text\` produces `text`.

Upvotes: 1

Ignatius
Ignatius

Reputation: 3332

This one is actually given as an example by John Gruber himself.

You can see from the Markdown documentation that you should write `` ` `` to get `.

Upvotes: 60

Related Questions