commonmark.py is a pure Python port of jgm’s commonmark.js, a Markdown parser and renderer for the CommonMark specification, using only native modules. Once both this project and the CommonMark specification are stable we will release the first 1.0 version and attempt to keep up to date with changes in commonmark.js .

commonmark.py is tested against the CommonMark spec with Python versions 2.7, 3.4, 3.5, 3.6, and 3.7.

Current version: 0.9.1

Installation $ pip install commonmark

Usage >>> import commonmark >>> commonmark.commonmark('*hello!*') '<p><em>hello!</em></p>

' Or, without the syntactic sugar: import commonmark parser = commonmark . Parser () ast = parser . parse ( "Hello *World*" ) renderer = commonmark . HtmlRenderer () html = renderer . render ( ast ) print ( html ) # <p>Hello <em>World</em><p/> # inspecting the abstract syntax tree json = commonmark . dumpJSON ( ast ) commonmark . dumpAST ( ast ) # pretty print generated AST structure There is also a CLI: $ cmark README.md -o README.html $ cmark README.md -o README.json -aj # output AST as JSON $ cmark README.md -a # pretty print generated AST structure $ cmark -h usage: cmark [-h] [-o [O]] [-a] [-aj] [infile] Process Markdown according to the CommonMark specification. positional arguments: infile Input Markdown file to parse, defaults to stdin optional arguments: -h, --help show this help message and exit -o [O] Output HTML/JSON file, defaults to stdout -a Print formatted AST -aj Output JSON AST

Contributing If you would like to offer suggestions/optimizations/bugfixes through pull requests please do! Also if you find an error in the parser/renderer that isn’t caught by the current test suite please open a new issue and I would also suggest you send the commonmark.js project a pull request adding your test to the existing test suite.