I need to convert markdown text to plain text format to display summary in my website. I want the code in python.
Advertisement
Answer
The Markdown and BeautifulSoup (now called beautifulsoup4) modules will help do what you describe.
Once you have converted the markdown to HTML, you can use a HTML parser to strip out the plain text.
Your code might look something like this:
from bs4 import BeautifulSoup from markdown import markdown html = markdown(some_html_string) text = ''.join(BeautifulSoup(html).findAll(text=True))