What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 133 Stack Exchange communities.

In this SO answer, I wanted to use the header Script component code in C# using the section title. However, the markdown syntax removed the hash sign (#) and it currently displays the text as Script component code in C. The only option that worked was ending the text with some character other than hash sign (#) like period (.).

Things I have tried:

Here are the list of different combinations I have tried based on the escape characters I found on this MSO post. I couldn't make any of these work as I expected it to.

###Script component code in C\#
###Script component code in C`#
###Script component code in C*#
###Script component code in C_#
###Script component code in C{#}
###Script component code in C[#]
###Script component code in C(#)
###Script component code in C##
###Script component code in C+#
###Script component code in C-#
###Script component code in C.#
###Script component code in C!#
###Script component code in C ##
###Script component code in C#.

Results:

Result screenshot

Searches on MSO:

http://meta.stackexchange.com/questions/33986/how-do-i-escape-in-code

This question seems to be about escaping hash sign in code and not the section title. I could not find other references when I searched for markdown hash sign.

Question:

How do I escape the hash sign if I want to use it in the section title?

Reason why I am asking now:

To answer @Cyborgx37's comment:

I rewrote the answer on February 8, 2013 completely with the latest release of the software to keep the answer up to date and also added more details to be more useful.

share|improve this question
1  
You waited 20 months to ask? ;) –  JDB Feb 20 '13 at 3:42

3 Answers 3

up vote 5 down vote accepted

You could simply use the alternative HTML syntax. Markdown parsing is disabled within HTML elements.

<h3>Script component code in C#</h3>

Or you could write the # as an HTML entity, they're allowed too.

###Script component code in C&#35;
share|improve this answer

You can use the other format for producing headers, by "underlining" the heading in question:

Script component code in C#
---------------------------- 

or

Script component code in C#
=============================

this produces

Script component code in C#

Underlining with - produces a level 2 h2 heading, while = produces a level 1 h1 heading. Admittedly neither of these are the h3 you're looking for, but they're all headings, you know. Semantically it's more accurate to use h2 as your first level subheading, since your question title is a h1.

Or you could just use HTML:

<h3>Script component code in C#</h3>

which produces

Script component code in C#

share|improve this answer

The markdown parser allows for any number of closing hash characters right before the newline, which are ignored.

You could simply add a space after the hash but before the newline, which is practically indistinguishable from your desired output:

Script component code in C#

In case you want to try figuring out a different way to skin this cat, you can have a look at the regex being used in the PageDown source:

/
    ^(\#{1,6})      // $1 = string of #'s
    [ \t]*
    (.+?)           // $2 = Header text
    [ \t]*
    \#*             // optional closing #'s (not counted)
    \n+
/gm
share|improve this answer

You must log in to answer this question.