DEV Community

Meghan (she/her)
Meghan (she/her)

Posted on

3 2

Escaping backticks in a code block block does not work

I swear I'm not trying to find bugs in the markdown parser XD but if you escape backticks while in a code block block then it does not work.

IE what I was trying to do is show someone how to format a code block and this is what happened

  • How to reproduce
  • did 3 backticks
  • new line, 3 backticks escaped with / but backslash
  • normal code
  • 3 more escaped backticks
  • 3 actual backticks to close the block

What that looks like when done can be seen below

alt


\`\`\`ruby
require "zlib"

def compress_file(file_name)
  zipped = "#{file_name}.gz"

  Zlib::GzipWriter.open(zipped) do |gz|
    gz.write IO.binread(file_name)
  end
end
\`\`\`
Enter fullscreen mode Exit fullscreen mode

edit: so it seems that in a post this works in post, but also includes the backticks. the garbled mess that I first encountered was from a comment so I'll post it there too

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (6)

Collapse
 
pythonperfection profile image
Eli Ostreicher

For the next person running into this issues, wrap the fenced block in ~~~ instead of backticks.
This will allow for any backticks inside the block to show as actual backticks.

Collapse
 
aloisseckar profile image
Alois Sečkár

awesome, thank you!

Collapse
 
allan-pg profile image
allan-pg

Thank you it really worked

Collapse
 
nektro profile image
Meghan (she/her) • Edited
\`\`\`ruby
require "zlib"

def compress_file(file_name)
  zipped = "#{file_name}.gz"

  Zlib::GzipWriter.open(zipped) do |gz|
    gz.write IO.binread(file_name)
  end
end
\`\`\`

okay, now its the same as above, idk what happened ¯\(ツ)

Collapse
 
cstayyab profile image
Muhammad Tayyab Sheikh

I came here looking for the solution of same problem. Turns out I missed closing backticks at one place in my blog. 😁😁😁 (By the way, I have just published it, you may read it here: dev.to/cstayyab/minimal-user-manag...

Collapse
 
hasanthesyrian profile image
HasanTheSyrian

I'm trying to do the same thing, but it's not working!

[Introduction](#introduction \\[1]\\)

## Introduction[1]
Enter fullscreen mode Exit fullscreen mode

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay