Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mcandre/8d76e076b2495fd8b36f439ec5033116 to your computer and use it in GitHub Desktop.

Select an option

Save mcandre/8d76e076b2495fd8b36f439ec5033116 to your computer and use it in GitHub Desktop.

GitHub-flavored Markdown does not use C-style escapes for escaping backticks inside spans. Instead, GFM uses double, significant whitespaced, backticks.

Two backticks, then a space, then a backtick, then a space, then two more backticks:

`` ` ``

produces:

`

@dwiyatci
Copy link
Copy Markdown

dwiyatci commented Dec 19, 2022

`
``
```
````
`foo${bar}baz`
...

@patbl
Copy link
Copy Markdown

patbl commented Feb 24, 2023

Can you quote backticks inside a code block inside a GitHub issue title? Using double backticks as the delimiter doesn't work in that context.

@jonathanneo
Copy link
Copy Markdown

jonathanneo commented Sep 14, 2023

@patbl

To display triple backticks in a fenced code block, wrap them inside quadruple backticks ````.

```
Look! You can see my backticks.
```

https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks

@patbl
Copy link
Copy Markdown

patbl commented Sep 14, 2023

@jonathanneo I was asking about GitHub issue titles. It seems like you can't use fenced code blocks in titles because they have just one line. Or am I missing something?

@jonathanneo
Copy link
Copy Markdown

jonathanneo commented Sep 14, 2023

@patbl I missed the part about issue titles. I'm not sure in that case.

@dwiyatci
Copy link
Copy Markdown

@kisaragi-hiu
Copy link
Copy Markdown

The reason this works is because Github (or, really, the original Markdown) is using the "use a different delimiter token" style of escaping inline code backticks. So if you need one backtick in the inline code, you start and end the inline code span with tokens made up of multiple backticks. It doesn't have to be double, it may as well be quaduple or 10 backticks. Start with 3, end with 3, then within the span you can include 1- or 2-backtick tokens verbatim.

Example:

``inline code using double backticks - a single ` is included verbatim``
```inline code using triple backticks - so `, ``, ```` etc. can all be included verbatim```
``````````That was ten, so ` `` ``` ```` etc. can all be included verbatim at the cost of the delimiter being a bit ridiculous``````````
``` ends with a backtick but surrounded by spaces, the spaces are removed` ```
```ends with a backtick but not surrounded by spaces, the final space is not removed` ```

Result:

inline code using double backticks - a single ` is included verbatim
inline code using triple backticks - so `, ``, ```` etc. can all be included verbatim
That was ten, so ` `` ``` ```` etc. can all be included verbatim at the cost of the delimiter being a bit ridiculous
ends with a backtick but surrounded by spaces, the spaces are removed`
ends with a backtick but not surrounded by spaces, the final space is not removed`

I've seen output from an AI agent write `Ctrl+`` ` `` as if the `` ` `` magically gets substituted with ` but that's not how it works.

As the final 2 examples show, if you need a span that ends with a backtick inside, first you need there to be a space between it and the ending backticks, and second that space can be removed from the output if there is also a space after the starting backticks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment