Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

A CommonMark renderer that outputs pretty plain text or compliant CommonMark.

Project Description
A `CommonMark-py`_<> renderer that outputs pretty plain text (not the original Markdown but something nicer for end users to see) or round-trips to compliant CommonMark.

The library was built against `CommonMark 0.25`_<> and `CommonMark-py 0.6.4`_<>.


import CommonMark
import CommonMarkPlainText

markdown_string = """# Hello!\n\nThis is [a link]("""

ast = CommonMark.Parser().parse(markdown_string)
text = CommonMarkPlainText.CommonMarkPlainTextRenderer().render(ast)


Which outputs::


This is a link <>.

Or using the CommonMarkToCommonMarkRenderer instead of the CommonMarkPlainTextRenderer, you get::


This is [a link](\.

Why have a special renderer for plain text?

* Links appear more friendly than in the []() notation.
* Indentation is normalized.
* There are many ways to specify a heading in CommonMark, so heading styles are normalized in the output.
* Entity references like "&#1234;" are turned into Unicode characters.


* The html_inline and html_block nodes are not supported and will raise a ValueError exception.
* Images are rendered as "[image]" plus their alt text.
* The CommonMarkToCommonMarkRenderer is pretty good but is not complete. It also has some additional limitations: it over-zealously backslash-escapes punctuation characters because it can't tell when it would be safe to not do so, lists next to each other may be combined, the loose/tight distinction of lists is not captured in output.


There is no reference output for what the plain text renderer should produce. But I've saved the output of all of the CommonMark spec examples into reference_output.txt so that as this library evolves we can see changes. To check for consistency with previous output of this library, run::

python3 > reference_output.txt
git diff

The CommonMarkPlainTextRenderer is tested by round-tripping CommonMark (parsing, then outputing it as CommonMark), and then parsing that and outputting to HTML. The final HTML should match the HTML that you'd get from just rendering to HTML in one step.
Release History

Release History

This version
History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
commonmark_to_text-0.0.1-py2.py3-none-any.whl (21.2 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel May 12, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting