I tried before to post a shell script that contained a ` character as an answer on Stack Overflow. The parser insisted on treating the backtick as formatting instead of part of code.
How can I include it?
5 Answers 5
If you do not want to use a pre-formatted block, there is still a way to do it inline.
From the "Code" section of the Markdown Documentation:
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.``
The above example renders like this (double quotes added): "There is a literal backtick (`) here."
Also of note, you can add spaces to render an inline code segment that starts with and/or ends with backticks:
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` ``
The above examples render like this (quotes added): "A single backtick in a code span: `" and "A backtick-delimited string in a code span: `foo`".
This may be implementation specific, but it looks like you can use N backticks to delimit any inline sequence that does not itself contain a maximal subsequence of exactly N backticks. For example, you can use three backticks to delimit a sequence that does not contain triple backticks (single, double, quadruple, quintuple, etc. are okay though).
Three quoting one, two and four: ``` one: ` two: `` four: ```` ```
Two quoting one, three, and four: `` one: ` three: ``` four: ```` ``
One quoting two, three and four: ` two: `` three: ``` four: ```` `
Yields:
Three quoting one, two and four: one: ` two: `` four: ````
Two quoting one, three, and four: one: ` three: ``` four: ````
One quoting two, three and four: two: `` three: ``` four: ````
Finally, for comments:
Ah, in comments one does need to escape using a backslash? `\`yes\``.
-
2Sometimes, at least,
double ` work in comments.Mark Hurd– Mark Hurd2013年08月01日 13:16:50 +00:00Commented Aug 1, 2013 at 13:16 -
3Ah, you're right @Mark, using a unique number of multiple opening and closing backticks works in comments too nowadays:
``one ` or three ``` within double backticks``nicely yieldsone ` or three ``` within double backticks. But in comments, it still doesn't work when adding a space to the delimiters, to allow for a backtick at the start or end of the code. Like to get Perl's$`it seems one needs`$\``in comments, as`` $` ``yields `` $` ``.Arjan– Arjan2013年12月22日 16:35:13 +00:00Commented Dec 22, 2013 at 16:35 -
3(Screenshot of the above comment, for future reference, as comments are rendered on the fly. So: if the implementation is changed, the above comment might render differently some day in the future.)Arjan– Arjan2013年12月22日 16:59:02 +00:00Commented Dec 22, 2013 at 16:59
-
Uau, costed me a bit to the the gist of the thing, dam ticks :)brasofilo– brasofilo2014年10月06日 22:13:50 +00:00Commented Oct 6, 2014 at 22:13
-
Is a trailing backtick not possible? You can see that this does not get formatted: ```kill `pidof chrome````Jonathon Reinhart– Jonathon Reinhart2015年01月17日 23:48:26 +00:00Commented Jan 17, 2015 at 23:48
-
3@JonathonReinhart: Try putting a space between the trailing backtick and the closing backticks:
```kill `pidof chrome` ```Chris Johnsen– Chris Johnsen2015年01月18日 04:38:04 +00:00Commented Jan 18, 2015 at 4:38 -
2upvote for the escaping note for comments.Akronix– Akronix2019年01月20日 10:41:52 +00:00Commented Jan 20, 2019 at 10:41
ChrisF's solution is the cleanest and easiest method, so I recommend using that whenever you can.
But if you find yourself needing it for inline code text and can tolerate needing to use <code> tags, its HTML entity `, demonstrated here: <code>this ` is a backtick</code> renders as this ` is a backtick.
-
3This works, but only in answers, not in comments (where inline HTML is not supported). However (at least as of this writing), just use
`(backticks) directly inside<code>elements - no need to resort to HTML entities.mklement0– mklement02015年02月26日 16:26:28 +00:00Commented Feb 26, 2015 at 16:26 -
1Interestingly,
`doesn't work.Fish Below the Ice– Fish Below the Ice2015年02月26日 17:11:45 +00:00Commented Feb 26, 2015 at 17:11 -
This worked flawlessy in WordPress, unlike double-backticks from the accepted answer.Joe– Joe2016年06月26日 23:39:11 +00:00Commented Jun 26, 2016 at 23:39
Put the code on a separate line and indent by 4 characters.
Like ` this
To show a single backtick formatted as inline code, there are three options:
`` ` ``(Opening and closing the code section with 2 or more backticks)<code>`</code><code>`</code>
-
1This is the correct answerkizzx2– kizzx22019年06月26日 16:44:19 +00:00Commented Jun 26, 2019 at 16:44
-
None of this 3 solutions worked for me when writing a code inline with backticks as an answer. The only solution was to put it in a new line and indented as in meta.stackexchange.com/a/55439/779583Pere Joan Martorell– Pere Joan Martorell2020年10月28日 12:01:16 +00:00Commented Oct 28, 2020 at 12:01
I needed to display the following on Stack Overflow: enter image description here
Using a double backtick to escape the entire sequence does not work:
``x```
I could almost get it to work by adding a space before the closing pair:
x`
but that wasn't quite right. I ended up using a <code> block:
x`
Also, as suggested by @Laurel, you can add spaces both before and after:
x`
-
1I wonder if you can use spaces on either side: `` x` ``. (Apparently not in comments).Laurel– Laurel2022年01月06日 13:42:23 +00:00Commented Jan 6, 2022 at 13:42
-
@Laurel well done!StayOnTarget– StayOnTarget2022年01月06日 21:04:02 +00:00Commented Jan 6, 2022 at 21:04
You must log in to answer this question.
Explore related questions
See similar questions with these tags.
`.