https://github.com/hukkin/mdformat-black
Mdformat plugin to Blacken Python code blocks
https://github.com/hukkin/mdformat-black
black commonmark markdown mdformat pyfmt python
Last synced: 4 months ago
JSON representation
Mdformat plugin to Blacken Python code blocks
- Host: GitHub
- URL: https://github.com/hukkin/mdformat-black
- Owner: hukkin
- License: mit
- Created: 2020-09-17T01:44:35.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2025-03-09T06:30:44.000Z (7 months ago)
- Last Synced: 2025-06-13T00:14:30.706Z (4 months ago)
- Topics: black, commonmark, markdown, mdformat, pyfmt, python
- Language: Python
- Homepage:
- Size: 52.7 KB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[]()
[]()# mdformat-black
> Mdformat plugin to Blacken Python code blocks## Description
mdformat-black is an [mdformat](https://github.com/executablebooks/mdformat) plugin
that makes mdformat format Python code blocks with [Black](https://github.com/psf/black).
## Usage
Install with:
```bash
pip install mdformat-black
```
You may pin Black dependency for formatting stability:
```bash
pip install mdformat-black black==22.1.0
```When using mdformat on the command line, Black formatting will be automatically enabled after install.
When using mdformat Python API, code formatting for Python will have to be enabled explicitly:
````python
import mdformatunformatted = "```python\n'''black converts quotes'''\n```\n"
formatted = mdformat.text(unformatted, codeformatters={"python"})
assert formatted == '```python\n"""black converts quotes"""\n```\n'
````## Usage as a [pre-commit](https://pre-commit.com) hook
Add the following to your `.pre-commit-config.yaml`:
```yaml
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.13 # Use the ref you want to point at
hooks:
- id: mdformat
additional_dependencies:
- mdformat-black
- black==22.1.0 # Pinning black here is optional
```