Mistune Markdown Parser
Mistune is a sane and fast Markdown parser for Python, offering various useful plugins and renderers. It is actively maintained, with the current version being 3.2.0, and receives regular updates to support newer Python versions and fix bugs.
Warnings
- breaking Mistune v3 introduced significant breaking changes compared to v2, particularly in custom renderer methods' parameters and the redesign of directives. Migrating existing code, especially custom plugins or renderers, will require updates.
- gotcha The default behavior for HTML escaping differs between `mistune.html()` and `mistune.create_markdown()`. `mistune.html()` does not escape raw HTML tags by default, while `mistune.create_markdown()` (without `escape=False`) *does* escape HTML.
- gotcha While a global `mistune.markdown()` function exists, for performance-critical applications or when using custom configurations and plugins, it is recommended to create and reuse a `Markdown` instance (e.g., via `mistune.create_markdown()`) rather than calling the global function repeatedly.
- gotcha Versions of Mistune v3 prior to 3.0.2 experienced a `RecursionError` when parsing complex lists.
Install
-
pip install mistune
Imports
- html
import mistune html_output = mistune.html(markdown_text)
- create_markdown
from mistune import create_markdown markdown = create_markdown(plugins=['strikethrough']) html_output = markdown(markdown_text)
Quickstart
import mistune markdown_text = """ # Hello, Mistune! This is **bold** text and `code`. - Item 1 - Item 2 """ html_output = mistune.html(markdown_text) print(html_output)