Recently, when I build PocketToWordpress. I really need a tool to convert HTML string to Markdown string, however none of them work perfectly, some shortages I found. None of them can handle indents well, indents in markdown will be code block, but in html, it does nothing. They cannot handle <a> with nofollow or new tab. The solution I found for solving this problem is using Jinja2. Jinja2 as a powerful rendering engine is usually used to generate HTML content, such as in Flask/Django frameworks, however, we can used it for markdown too. How to use Jinja2 generate markdown? The easiest way to generate markdown will be using string formatting, something like in Python. If giving up HTML tags, Jinja2 will became a powerful string format-er too. Jinja2 Templates in HTML and Markdown The original way when I generate HTML. For the HTML string generated from the above template, you cannot render to markdown properly, because of indents and the <a> tags. But if we switch to this, this can work perfectly. This markdown template, if you use a HTML… Read More »How to generate markdown through Jinja2?