blacken-docs

1.20.0 · active · verified Thu Apr 16

blacken-docs is a command-line tool that formats Python code blocks within various documentation files (Markdown, reStructuredText, LaTeX, and Python docstrings) using the opinionated `Black` formatter. It operates by rewriting files in place. The library is currently at version 1.20.0, actively maintained, and releases occur periodically to support new Python versions and `Black` features.

Common errors

Warnings

Install

Quickstart

Install `blacken-docs` and run it from the command line on individual files or using glob patterns. The most common and recommended usage is as a `pre-commit` hook to automate formatting documentation code blocks.

pip install blacken-docs

# Format a specific Markdown file
blacken-docs README.md

# Format all reStructuredText files in the current directory
blacken-docs *.rst

# Example .pre-commit-config.yaml entry (recommended):
# See https://github.com/adamchainz/blacken-docs for latest revision
# - repo: https://github.com/asottile/blacken-docs
#   rev: v1.20.0 # Use the latest stable tag
#   hooks:
#     - id: blacken-docs
#       additional_dependencies: ['black==24.4.0'] # Pin Black version!

view raw JSON →