开发者

How to convert markdown (WMD) text to plain text

I am saving both 开发者_JS百科the markdown text and html versions of text in my database for my Q&A site.

When users browse the questions they are viewing snippets 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.


Another solution is to use markdown XSLT file.

For example : HTML To Markdown Text

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜