Python bindings for the Comrak Rust library, a fast CommonMark/GFM parser
Maintained. Last release 4 months ago, commits in 5 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install comrakcomrak
Python bindings for the Comrak Rust library, a fast CommonMark/GFM parser.
Currently tracking comrak 0.54.
Installation
pip install comrak
Requirements
- Python 3.9+
Usage
>>> import comrak
>>> comrak.render_markdown("# Hello")
'<h1>Hello</h1>\n'
CommonMark output
render_commonmark renders Markdown back to normalized CommonMark instead of
HTML. It takes the same extension_options/parse_options/render_options
as render_markdown:
>>> comrak.render_commonmark("- one\n- two\n- three")
'- one\n- two\n- three\n'
>>> opts = comrak.RenderOptions()
>>> opts.list_style = comrak.ListStyle.Plus
>>> comrak.render_commonmark("- one\n- two\n- three", render_options=opts)
'+ one\n+ two\n+ three\n'
Options
Every option in comrak's Extension, Parse and Render structs is exposed,
with the same name and the same default:
>>> opts = comrak.ExtensionOptions()
>>> comrak.render_markdown("foo :smile:", extension_options=opts)
'<p>foo :smile:</p>\n'
>>> opts.shortcodes = True
>>> comrak.render_markdown("foo :smile:", extension_options=opts)
'<p>foo 😄</p>\n'