cmarkgfm: GitHub Flavored Markdown (GFM) Parser

2025.10.22 · active · verified Wed Apr 15

cmarkgfm provides minimalist Python bindings to GitHub's fork of cmark, the C reference implementation of CommonMark. It allows parsing and rendering CommonMark and GitHub Flavored Markdown (GFM) to HTML, offering fast and accurate conversions. The library is actively maintained with frequent releases, currently at version 2025.10.22, and aims to stay up-to-date with Python versions and the underlying `cmark-gfm` C library.

Warnings

Install

Imports

Quickstart

This example demonstrates rendering both standard CommonMark and GitHub Flavored Markdown to HTML. It also shows how to use advanced rendering options, such as enabling smart quotes and GitHub-style code block language tags.

import cmarkgfm
from cmarkgfm.cmark import Options as cmarkgfmOptions

markdown_text = "# Hello CommonMark\n\nThis is **bold** text."
html_commonmark = cmarkgfm.markdown_to_html(markdown_text)
print("CommonMark HTML:\n", html_commonmark)

gfm_text = "This is GitHub Flavored Markdown with a ~strikethrough~ and a [link](https://github.com)."
html_gfm = cmarkgfm.github_flavored_markdown_to_html(gfm_text)
print("\nGFM HTML:\n", html_gfm)

# Example with options: smart quotes and GitHub pre-lang
options = (
    cmarkgfmOptions.CMARK_OPT_SMART |
    cmarkgfmOptions.CMARK_OPT_GITHUB_PRE_LANG
)
markdown_with_options = "“Smart quotes” and ```python\nprint('hello')\n```"
html_with_options = cmarkgfm.markdown_to_html(markdown_with_options, options)
print("\nHTML with Options:\n", html_with_options)

view raw JSON →