Escaping special characters in markdown

These characters need to be escaped in Markdown in order to appear as literal characters instead of performing some markdown functions:

\ ` * _ { } [ ] ( ) # + - . !

Special escaping for hash (#)

You can usually escape a # with the \ character like others in the above list, but if your hash appears on the same line as an h1/h2/h3 which themselves start with #, ##, or ### then you need extra escaping for the inline #. In this case, add another # at the end of the line to trick the markdown compiler into closing matching hashes. This behavior may vary between markdown implementations.

Special escaping for backtick (`)

The simple way to escape a backtick is with the \ character before it. If you just write a ` by itself, then any text between it and the next matching ` MAY be treated as quoted code and the actual backticks won't be seen (sometimes it still works).

You can escape a backtick by putting it in a code block, any block of text which is preprended by 4 spaces on each line.

Multiple consecutive ` will print out, e.g. `` or ```.

You can also use HTML entities to print any special characters and in this case it would be `

Handling underscores

In Markdown, a word or string which begins and ends with the underscrore () will appear _emphasized. But in other cases, using an underscore should be fine:

Examples:

  • _test
  • test_
  • te_st
  • `_test

Add new comment