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

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:

<h1>test</h1>

test

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 stackoverflow.com Mar 21 '11 at 14:53

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

2  
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
2  
It's because this question belongs on meta; it's a great question though. –  Sam Mar 21 '11 at 14:52
3  
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
1  
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
1  
The close menu lists a bunch of reasons. People have to pick one of them. –  Quentin Mar 21 '11 at 14:53
1  
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
2  
@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. stackoverflow.com/questions/5379469/… –  Chevex Mar 21 '11 at 15:02
add comment

1 Answer 1

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
add comment

You must log in to answer this question.

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