So I have a cms where users can enter content through cuteeditor, which works fine and then display this data on my website. One thing which happens rarely but annoying is that users enter certain mark up in their text which makes the font look different than the other fonts on the page i.e.
<span style="font-size: 11pt">Special Olympics Ireland provides year round sports training and athletic competition in a variety of Olympic type sports for persons with intellectual disabilities in </span><span style="font-size: 11pt">Ireland</span><span style="font-size: 11pt"> and </span><span style="font-size: 11pt">Northern Ireland</span><span style="font-size: 11pt"> in accordance with and furtherance of the mission, goal and founding principles of the international Special Olympics movement.</span>
Basically what I want to do is
String.Replace("<span style="font-size: 11pt">","")
But ofcourse that will only capture the above case the next time they could use font size 8,9 or 10 whatever so the filter method would have to be smart like that.
Any ideas ?
SO at the moment I have something like
testSpan = Regex.Replace(testSpan, @”\s]+))?)+\s*|\s*)/?>”, String.Empty);
But it gets rid of all html basically I just want to get rid of tags
If you want to follow StackOverflow’s example, you could create a white-list of allowed HTML tags, and strip out the rest.
Following are the code snippets Jeff Atwood uses to sanitize and balance HTML tags in StackOverflow’s user-generated content.
Update
It looks like Refactormycode is dead. Here’s some code that I captured before that happened: