63

I have the following code on a README.md file on GitHub, where I am trying to display the hash sign on a header (I am trying to escape it using the \ symbol) like so:

### C\#
* [Beginning Game Programming with C#](https://www.coursera.org/course/gameprogramming)

However it renders like so:

Not good

I obviously want the hash sign to appear on the header, and I also tried to use a double backslash, but it didn't work. How do I get the pound sign to appear?

EDIT: the linked question deals with GitHub links, my question is to do with headers on a .md file.

shim
  • 9,289
  • 12
  • 69
  • 108
ifma
  • 3,673
  • 4
  • 26
  • 38
  • possible duplicate of [Escape pound or number sign in Github issue tracker](http://stackoverflow.com/questions/20532546/escape-pound-or-number-sign-in-github-issue-tracker) – lschuetze Aug 25 '15 at 06:03
  • 5
    I don't think this is a good duplicate because this context is different - header/title/section vs. linked id. – user2864740 Aug 25 '15 at 06:07
  • 1
    @The Imp, you may want to report this as a bug to GitHub (or at least whatever implementation of Markdown they are using. @VonC's answer solved the problem because without the extra hash, the parser was mistaking the hash in `C#` for a closing hash. However, the parser apparently fails to account for that hash being escaped, which should be considered a bug. I expect that the parser is only taking into account escaping when processing inline markup. Usually that works fine, This is one of the few edge cases where escaping should to be considered for block level markup. – Waylan Aug 27 '15 at 18:07
  • Tip: When US users says 'pound sign', they mean a hash (#). – Michael Scheper Sep 01 '16 at 18:30

3 Answers3

38

You could try and add a matching '#', followed by one extra '#':

### C# #
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 6
    @Maxpm As [commented above](https://stackoverflow.com/questions/32196555/how-to-escape-the-hash-sign-in-a-github-markdown-header-backslash-is-not-w/32196591#comment52393147_32196555): "because without the extra hash, the parser was mistaking the hash in C# for a closing hash." – VonC Mar 26 '19 at 07:19
29

As in this answer you can insert an invisible character before the octothorpe, such as ​.

shim
  • 9,289
  • 12
  • 69
  • 108
15

Add an extra space after ### C\#.

serverpunk
  • 10,665
  • 15
  • 61
  • 95
Tagir Valeev
  • 97,161
  • 19
  • 222
  • 334