Hello, I am saving both the markdown text and html versions of text in my database. I have a question and answer site. When users browse the questions they are viewing snippits of markdown. They should only be viewing plain text just like when browsing questions on stackoverflow there are no markdown text or html text shown. Is there a way to convert either markdown or html text to plain text?
Questions on StackOverflow are being viewed in HTML not plain text. They are sanitized using Jeff Atwood's HTML sanitizer and then converted to HTML using MarkDownSharp.
I asked this question a few weeks back and the solution I ended up with was to store the raw markdown in the database and then transform it when it's shown to the visitor.
Here's how I'm sanitizing my Markdown
''# Because some people can be real ass holes and try to submit bad data (scripts and crap)
''# we have to modify the "About" content in order to sanitize it. At the same time, we
''# transform the Markdown into valid HTML
user.About = Trim(Utilities.HtmlSanitizer.Sanitize(MarkDownSharp.Transform(user.About)))
Since MarkdownSharp is open source, I'm sure you could dig into the source code and remove the additional tags that you don't want to see in the preview.
EDIT:
Since in my example I'm sanitizing the HTML before converting the markdown, I think you would have to remove the <b>
or <strong>
tags in both the HtmlSanitizer and MarkdownSharp. The reason for this is that you'll need to sanitize raw html tags AND markdown tags.