Convert Rich Markdown to Plain Text

How to convert rich markdown to plain text? Therefore, it can be used, for example, to describe OpenGraph on Facebook.

I am using MarkdownSharp and does not seem to have this feature. Before I was going to reinvent the wheel, I thought to ask first here.

Any hints on the implementation strategy are welcome!

Example

The Monorailcat --------------- ![Picture of a Lolcat](https://media1.giphy.com/media/c7goDcMPKjw6A/200_s.gif) One of the earliest pictures of **monorail cat** found is from the website [catmas.com's blog][1] section, dated from November 2, 2006. [1]: http://catmas.com/blog 

Must be converted to:

 The Monorailcat One of the earliest pictures of monorail cat found is from the website catmas.com's blog section, dated from November 2, 2006. 
+7
c # markdown markdownsharp
source share
2 answers

You have several options.

  • As stated in the comment, you can convert to HTML and then convert HTML to plain text. This is probably the most reliable and consistent cross-platform solution.

  • Switch to a library that can convert several formats, including the desired formats. Pandoc would be an example of such a tool.

  • Use the Markdown analyzer, which displays the AST . Although these parsers typically provide an HTML renderer (accept ASTs as HTML input and output), you can create your own renderer that outputs whatever format you want.

In fact, it turns out that Pandoc is also an example of number 3. Just existing simple text rendering already exists. Of course, if you are looking for C # lib, then Pandoc may not suit your needs. And I don't know about any C # libs that satisfy this need (the reference implementation uses regex string replacement, and many (most?) Parsers have followed this example). However, I am not familiar with any of the Markdown libraries in C #, and this is not a good place to make recommendations. However, there is a long, though incomplete, list of parsers here . You can find something there.

+4
source share

Some libraries exist to help remove markdown syntax, such as removemarkdown or strip-markdown .

0
source share

All Articles