escapingmarkdowngithub-flavored-markdownbackticks

How does one escape backticks in markdown?


I am writing some documentation in markdown and I want to document how to create a text file using a bash HEREDOC. Here is the command I want to document:

# cat > /tmp/answers.txt <<EOT
> value1=blah
> value2=something else
> value3=`hostname`
> value4=onetwothree
EOT

In markdown one uses the ` to render the text as "code" I have tried doing this ...

`# cat > /tmp/answers.txt <<EOT`
`> value1=blah`
`> value2=something else`
`> value3=\`hostname\``
`> value4=onetwothree`
`EOT`

... but that results in something that looks like this ...

# cat > /tmp/answers.txt <<EOT
> value1=blah
> value2=something else
> value3=\

hostname
> value4=onetwothree
EOT


Solution

  • This code block below does the trick.

    ```
    # cat > /tmp/answers.txt <<EOT
    > value1=blah
    > value2=something else
    > value3=`hostname`
    > value4=onetwothree
    EOT
    ```
    

    The three Backtick means it's snippet of code and a snippet must end with three more Backtick.

    For more help with Markdown refer this CheatSheet.