skillfed

mdformat-black

Mdformat plugin to Blacken Python code blocks

mdformat-black v0.1.1 114.4K downloads/30d#12,299 on PyPI9
Permissive license MIT AGING released

What it is and what it does

mdformat-black is a plugin that extends mdformat to apply Black's Python code formatting rules to Python code blocks within Markdown files. When installed, mdformat automatically recognizes and formats Python code blocks using Black's conventions—converting quote styles, enforcing line length, and applying other Black rules—while leaving the rest of your Markdown untouched.

The plugin works both from the command line (automatically after install) and programmatically via mdformat's Python API (where you must explicitly enable it by passing `codeformatters={"python"}` to mdformat.text()). It requires Python >=3.6,<4.0 and depends on mdformat and black as runtime dependencies.

Use it for:

  • Automatically format Python code examples in technical documentation to match your project's Black style.
  • Ensure consistency between code snippets in README files and your actual codebase formatting.
  • Integrate Python code block formatting into a Markdown linting or CI pipeline alongside mdformat.
  • Format Python code blocks in blog posts or tutorials written in Markdown without manual editing.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

A plugin for mdformat that automatically formats Python code blocks in Markdown files using Black's code style rules.

Yes, if you use mdformat and want Python code blocks in your Markdown to follow Black's style. The low install friction, permissive license, and lack of known vulnerabilities make it straightforward. However, the aging maintenance status (last release 2020-09-24) means you should verify compatibility with your current Black and mdformat versions before relying on it in production workflows.

Install

mdformat-black on PyPI

pip

pip install mdformat-black

uv

uv add mdformat-black

poetry

poetry add mdformat-black

Installing mdformat-black

Before you install

Low install friction with just two runtime dependencies. The package is aging—last release was 2020-09-24 and last commit 2025-03-09—but remains unarchived.

License in practice

MIT license is permissive; you can use, modify, and distribute freely with minimal restrictions.

Quickstart

pip install mdformat-black

import mdformat
unformatted = "```python\n'''black converts quotes'''\n```\n"
formatted = mdformat.text(unformatted, codeformatters={"python"})
assert formatted == '```python\n"""black converts quotes"""\n```\n'

Requires mdformat and black to be installed; Python >=3.6,<4.0

Verify before relying

  • Whether the package works reliably with recent versions of black and mdformat beyond classifier claims.
  • Whether there are known incompatibilities with Python 3.9+ despite the 'supports_current' designation.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.6,<4.0)
Install friction low — pure-Python wheel
Runtime dependencies 2 — mdformat, black
Maintenance aging — 2,150 days since the last release
Last repo commit
First released
Downloads 114,372/month — #12,299 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: mdformat_black-0.1.1-py3-none-any.whl

Keywords: mdformat, markdown, commonmark, formatter

License :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Topic :: DocumentationTopic :: Text Processing :: MarkupTyping :: Typed

Tags

markdown python code formattermdformat black pluginformat python in markdownblack code blocks markdownmarkdown code formattingpython block formattermdformat plugin
markdown-formattingcode-style-enforcement

More Markup packages