Skip to main content

Minimal bindings to GitHub's fork of cmark

Project description

Minimalist Python bindings to GitHub’s fork of cmark.


This package is published on PyPI as cmarkgfm and can be installed with pip or pipenv:

pip install --user cmarkgfm
pipenv install cmarkgfm

Wheels are provided for macOS, Linux, and Windows for Python 3.6, 3.7, 3.8, 3.9, 3.10 and 3.11.


High-level usage is really straightforward. To render normal CommonMark markdown:

import cmarkgfm

html = cmarkgfm.markdown_to_html(markdown_text)

To render GitHub-flavored markdown:

import cmarkgfm

html = cmarkgfm.github_flavored_markdown_to_html(markdown_text)

Advanced Usage


Both rendering methods markdown_to_html and github_flavored_markdown_to_html have an optional options argument that can be used to activate options of cmark. For example:

import cmarkgfm
from cmarkgfm.cmark import Options as cmarkgfmOptions

options = (
    | cmarkgfmOptions.CMARK_OPT_SMART
html = cmarkgfm.markdown_to_html(markdown_text, options)

The options are:




Allows rendering unsafe HTML and links.


Prevents rendering unsafe HTML and links.


Render curly quotes, en/em-dashes, ellipses


Consolidate adjacent text nodes.


Renders line breaks within paragraphs as <br>


Render soft line breaks as spaces.


Adds data-sourcepos to HTML tags indicating the corresponding line/col ranges in the input


Parse footnotes.


Validate UTF-8 in the input before parsing, replacing illegal sequenceswith the replacement character U+FFFD.


Use GitHub-style tags for code blocks.


Be liberal in interpreting inline HTML tags.


Only parse strikethroughs if surrounded by exactly 2 tildes. Gives some compatibility with redcarpet.


Use style attributes to align table cells instead of align attributes.

Unsafe rendering

Since version 0.5.0, the default behavior is safe. In earlier versions, the default behavior is unsafe, as described below. To render potentially unsafe HTML since 0.5.0 pass the CMARK_OPT_UNSAFE option.

CommonMark can render potentially unsafe HTML, including raw HTML, raw Javascript, and potentially unsafe links (including links that run scripts). Although github_flavored_markdown_to_html prevents some raw HTML tags (including script) from being rendered, it does not block unsafe URLs in links.

Therefore it is recommend to call the rendering method with the SAFE option turned on. The safe option does not render raw HTML or potentially dangerous URLs. (Raw HTML is replaced by a placeholder comment; potentially dangerous URLs are replaced by empty strings.) Dangerous URLs are those that begin with javascript:, vbscript:, file:, or data: (except for image/png, image/gif, image/jpeg, or image/webp mime types) To do this, use:

# cmarkgfm<0.5.0
import cmarkgfm
from cmarkgfm.cmark import Options as cmarkgfmOptions

html = cmarkgfm.markdown_to_html(markdown_text, options=cmarkgfmOptions.CMARK_OPT_SAFE)
# or
html = cmarkgfm.github_flavored_markdown_to_html(markdown_text, options=cmarkgfmOptions.CMARK_OPT_SAFE)

If you trust the markdown text to not include any unsafe tags and links, then you may skip this.


Pull requests are welcome. :)


This project is under the MIT License. It includes components under differing copyright under the third_party directory in this source tree.

Download files

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

Source Distribution

cmarkgfm-2024.1.14.tar.gz (146.7 kB view hashes)

Uploaded source

Built Distributions

cmarkgfm-2024.1.14-cp312-cp312-win_amd64.whl (127.3 kB view hashes)

Uploaded cp312

cmarkgfm-2024.1.14-cp312-cp312-win32.whl (116.8 kB view hashes)

Uploaded cp312

cmarkgfm-2024.1.14-cp311-cp311-win_amd64.whl (127.3 kB view hashes)

Uploaded cp311

cmarkgfm-2024.1.14-cp311-cp311-win32.whl (116.8 kB view hashes)

Uploaded cp311

cmarkgfm-2024.1.14-cp310-cp310-win_amd64.whl (127.3 kB view hashes)

Uploaded cp310

cmarkgfm-2024.1.14-cp310-cp310-win32.whl (116.8 kB view hashes)

Uploaded cp310

cmarkgfm-2024.1.14-cp39-cp39-win_amd64.whl (127.3 kB view hashes)

Uploaded cp39

cmarkgfm-2024.1.14-cp39-cp39-win32.whl (116.8 kB view hashes)

Uploaded cp39

cmarkgfm-2024.1.14-cp38-cp38-win_amd64.whl (127.3 kB view hashes)

Uploaded cp38

cmarkgfm-2024.1.14-cp38-cp38-win32.whl (116.8 kB view hashes)

Uploaded cp38

cmarkgfm-2024.1.14-cp37-cp37m-win_amd64.whl (127.3 kB view hashes)

Uploaded cp37

cmarkgfm-2024.1.14-cp37-cp37m-win32.whl (116.8 kB view hashes)

Uploaded cp37

cmarkgfm-2024.1.14-cp36-cp36m-win_amd64.whl (139.1 kB view hashes)

Uploaded cp36

cmarkgfm-2024.1.14-cp36-cp36m-win32.whl (124.4 kB view hashes)

Uploaded cp36

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page