Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 157 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

I am curious how SO goes about removing HTML tags from posts. I just started using their MarkdownSharp project. By default MarkdownSharp encodes any HTML within code blocks like this:

<span style="color: red;">I am HTML</span>

But if I do the same thing outside of a code block it simply doesn't show up at all:

I am HTML <- tags are removed.

But they have whitelisted certain tags for basic markup, like the header tags:



I can also type HTML entities like &gt; doesn't get re-encoded, it will actually show up as a >

I'm sure the tags that get removed are being removed BEFORE the content is passed to markdown, as markdown generated HTML tags would likely be removed if this tag removal code was run after markdown handled it.

Does anyone know how SO accomplishes this, and if it is code that is available to use? Alternatives are acceptable also. I'm hoping to find something in C# as my project is C# ASP.NET MVC 3.

Thanks in advance!

share|improve this question

migrated from Mar 21 '11 at 14:53

This question came from our site for professional and enthusiast programmers.

Not sure why I get close votes, I feel like I was very specific and clear. If you have an issue please comment and let me know instead of just voting to close with no reason why. – Chevex Mar 21 '11 at 14:48
It's because this question belongs on meta; it's a great question though. – Sam Mar 21 '11 at 14:52
It's getting close votes because this belongs to meta since it's related to inner workings of stackoverflow. – Robert Koritnik Mar 21 '11 at 14:53
The 2 close votes cite "off topic". It doesn't seem such a bad question to me. I think it would be better if you asked how you could do it in your setting rather than how SO does it. – David Heffernan Mar 21 '11 at 14:53
The close menu lists a bunch of reasons. People have to pick one of them. – Quentin Mar 21 '11 at 14:53
Well I didn't think it was specifically related to SO since I am also welcoming alternatives that produce the same behavior and would like it for my own project. I am not discussing SO explicitly, just asking how it accomplishes a behavior. Seems a programming question to me. – Chevex Mar 21 '11 at 14:55
@Chevex: It does seem programmer's question but you should rephrase it differently. You shouldn't be asking how stackoverflow does it, but that you're using the markdown editor and would like to accomplish certain things that don't work as intended out of the box. You can reference that stackoverflow does it this and that way, that you'd like to accomplish as well. But don't ask how stackoverflow's doing it. It will migrate to meta. – Robert Koritnik Mar 21 '11 at 14:57
@Chevex: And don't get angry or annoyed because of it. You will likely get better answers rephrasing it anyway. Everything's for the better. – Robert Koritnik Mar 21 '11 at 15:00
My being "angry or annoyed" is an assumption on your part. Reposted with note of clarification.… – Chevex Mar 21 '11 at 15:02
up vote 5 down vote accepted

They use the HtmlSanitzer written by Jeff Atwood.

share|improve this answer
Thank you for this :) – Chevex Mar 21 '11 at 15:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .