How do I escape three backticks surrounded by a codeblock in Markdown?
Asked Answered
E

2

37

First, I'd like to say that I've read some recommended questions that may seem to answer my question, but they're all about escape single backtick in markdown. I've tried but none of them seem to work.

Here's what I've tried.

  1. Double backtick - single space - three backticks.

    To avoid any problems, I use image to discribe.

    and it seems to be good in my markdown editor except missing the breakline. But bad luck, it seems terrible on Hexo blog.

    Then I test in Github for luck. And, difference shows:

    Shown in github.

  2. Use backslash.

Unfortunately, it shows directly instead of escape the backtick.

Now, my question is, it works well here in Stack Overflow, but not in my blog. What else I should try except using html tag, or is it the only way I should go? Is it the issue with my usage or my blog theme?

Equestrian answered 5/8, 2015 at 6:47 Comment(0)
C
72

In addition to nesting a fenced block inside an indented block (as demonstrated in another answer), you can also nest one fenced block inside another fenced block by using a different number of backticks (as you have tried). However, you must keep each set of deliminators on a separate line. And most implementations require three or more backticks (your use of 2 is another failure point). For example, notice that in the following example the outer block uses four backticks whereas the inner block uses three backticks:

````
```
UIBarButtonItem *search = [[UIBarButtonItem alloc]
```
````

In many implementations that will render as:

```
UIBarButtonItem *search = [[UIBarButtonItem alloc]
```

You may find this is not supported properly with some implementations however.

As an alternative, if the implementation you are using also supports tildes (~) as fenced code block deliminators, you can use those instead:

~~~
```
UIBarButtonItem *search = [[UIBarButtonItem alloc]
```
~~~

Again, never use less that three deliminator characters in a group and always include each group on a separate line by itself.

Confessedly answered 5/8, 2015 at 13:45 Comment(0)
M
7

There are two ways to represent code blocks in most Markdown implementations:

You can combine these techniques, causing the triple backticks from your fenced block to be treated part of the indented code block, e.g.

    ```
    UIBarButtonItem *search = [[UIBarButtonItem alloc]
    ```

This snippet renders like this on Stack Overflow:

```
UIBarButtonItem *search = [[UIBarButtonItem alloc]
```
Milliard answered 5/8, 2015 at 12:21 Comment(1)
This is a great one because it turns out that pressing the tab key on a selection in a github comment window indents the selection, so it is very easy to do and clean.Houle

© 2022 - 2024 — McMap. All rights reserved.