Pymdown Extensions

10.21.2 · active · verified Tue Mar 31

Pymdown Extensions is an extension pack for Python Markdown, offering a comprehensive collection of features to enhance Markdown rendering. It provides over 30 extensions for capabilities such as enhanced code blocks with highlighting, content tabs, emoji support, and mathematical notation. Currently at version 10.21.2, the library is actively developed with a consistent release cadence.

Warnings

Install

Imports

Quickstart

Initialize a Markdown converter with `pymdown-extensions` by listing their names (e.g., `pymdownx.superfences`, `pymdownx.highlight`) in the `extensions` argument. The example demonstrates basic Markdown conversion with code block highlighting and emoji support.

import markdown

md_text = '''
# Hello Pymdown!

This is a simple markdown with `inline code`.

```python
# SuperFences and Highlight example
def greet(name):
    print(f"Hello, {name}!")

greet("World")
```
''')

# To use Pymdown Extensions, pass their names (prefixed with 'pymdownx.')
# to the 'extensions' argument of markdown.Markdown.
# 'superfences' allows nested code blocks, and 'highlight' provides syntax highlighting.
html = markdown.Markdown(
    extensions=[
        'pymdownx.superfences',
        'pymdownx.highlight',
        'pymdownx.emoji'
    ]
).convert(md_text)

print(html)

view raw JSON →