github / markup

Determines which markup library to use to render a content file (e.g. README) on GitHub
MIT License
5.84k stars 3.4k forks source link

Backticks are not escaped with the escape character (`\`) #363

Closed zspencer closed 10 years ago

zspencer commented 10 years ago

I believe the following code:

`\``

should render:

<p><code>`</code></p>

as specified in the markdown syntax reference

A "kinda workaround" is to use &#96; in place of the backtick (`) character; however this doesn't work inside of backticks: &#96;

Interestingly enough, the github basics of markdown documentation itself does have backticks inside of a code block.

Also interesting is almost no processor seems to get this right.

Is 9:30AM to early to start drinking?

zspencer commented 10 years ago

Never mind; it appears the proper syntax for inserting backticks inside of codeblocks is to use more backticks: `

Edit with example: ``console.log(`Now this is ${excitingAdventureWhichIsLegallyDistinctButNotDissimilarToPodracing}`) ``

amm-catapult commented 8 years ago

Here are more examples:

Just keep using more and more contiguous leading (and hence trailing) backticks with spaces inside them, per the pattern above, to go as crazy as you like :) For example:

`Oh you want FIVE backticks? ````` You'll need SIX to lead/trail, then :)` ...becomes...

Oh you want FIVE backticks? ````` You'll need SIX to lead/trail, then :)

psharma9145 commented 6 years ago
<p>test<p>
pyzae commented 5 years ago

ive found that in triple-backtick code blocks, following any backticks with zero-width spaces allows any number of backticks in a row without breaking out of the code block

m7stock commented 5 years ago

@pyzae I just want to mention that everyone who copy-pastes these zero-width spaces can have a hard time depending on his context... We should not release them into the wild.

pyzae commented 5 years ago

@matthiasstock what do you mean a hard time depending on his context? do you mean people copy-pasting out of the code blocks not realizing there are invisible characters there?

m7stock commented 5 years ago

@pyzae Yes, I just wanted to point out to later readers that there can be problems with these zero-width spaces in code examples. A code interpreter (in my context) generated a hard to understand error message.

fireattack commented 5 years ago

I'm very confused by the examples in https://github.com/github/markup/issues/363#issuecomment-200097074, did something change?

mbrowne commented 5 years ago

It seems that this only works with blocks of code starting on a new line, not inline code blocks.

masaeedu commented 4 years ago

I wrote the following commit message:

    Remove unnecessary wrapping

    Made the classic error when testing of assuming that this: ``-1 `mod` 3``

    parses as this: ``(-1) `mod` 3``

    when it actually parses as this: ``-(1 `mod` 3)`

But the way this is rendered in Github is kind of wonky:

image

Am I misunderstanding the Markdown specification?

EDIT: Just noticed I have a typo on the last line (I'm missing a closing backtick), but this doesn't seem to work on the other lines either.

fireattack commented 4 years ago

Seems to work fine here in the comments? See: -1 `mod` 3

magni- commented 4 years ago

Seems to work fine here in the comments? See: -1 `mod` 3

That does not work if the inner backticks are at the start/end of the inline code: `killpgrep -f rspec```

thegiantbeast commented 3 years ago

@magni- you can try:

`` `the-text-between-backtick` ``

You need to basically have a double backtick with a space (before and after). So in your case if you put a space after the first backtick at the end, it will work, ex: kill `pgrep -f rspec`

hepcat72 commented 3 years ago

Do you have to have spaces on both ends to avoid a space?

  1. No spaces, no code: `git grep ">pre(@"git rev-list --all```
  2. 1 space, code with extra space: git grep ">pre(@" `git rev-list --all`
  3. flanking spaces (we'll see): git grep ">pre(@" `git rev-list --all`
hepcat72 commented 3 years ago

Huh... That's really strange. No trailing ending space in case 2, but the same markdown in a comment on an issue in our (private) repo shows a trailing space inside the in-line code. Why would that be? Let me try the whole sentence:

According to git grep ">pre(@" `git rev-list --all`, that line in joblog.pl is the only call of pre with an array argument in the entire history of the repo. And the blame claims it has been that way since laurie's initial checkin 17 months ago.

hepcat72 commented 3 years ago

Yep. Why the differing behaviors? Is it because the line ends with git grep ">pre(@" `git rev-list --all`

hmmm...

hepcat72 commented 3 years ago

Perhaps.

gennaro-tedesco commented 3 years ago

It seems that this only works with blocks of code starting on a new line, not inline code blocks.

I confirm that with inline code blocks none of the examples above works unless the backticks are in the middle of the sentence and not at the boundaries.

arencambre commented 2 years ago

EDIT: Per the next comment, it is documented.

Since three backticks has special meaning to Github, the following needs to be made clear in Github's documentation: If you need to show three backticks in your code block, then surround the code block with four-backtick delimiters.

pixelstuermer commented 2 years ago

Since three backticks has special meaning to Github, the following needs to be made clear in Github's documentation: If you need to show three backticks in your code block, then surround the code block with four-backtick delimiters.

I guess they do so: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#fenced-code-blocks

shmup commented 2 years ago

How might I do render: "<CR> where the " is a backtick?

Ok I got it, phew. Just use a <code> block.. though I still have to escape the <CR>, heh.

<code>`\<CR\></code>

Ala.. `\<CR>

xiebruce commented 1 year ago

I think this should update to the documentation: Basic writing and formatting syntax, the documentation seems didn't mention this.

Neme12 commented 6 months ago

Come on, this is such a simple thing.

Ashvith10 commented 1 month ago

There's still issues with having a single backtick in a fenced codeblock. And no amount multiple backticks seem to fix this.

jacobtomlinson commented 1 month ago

I wanted a single backtick within an inline code block. This post helped me figure it out.

`` ` `` gives `