Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 21 days 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 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-02T09:40:33.000Z (about 2 months ago)
- Last Synced: 2024-10-13T23:11:36.844Z (about 1 month ago)
- Topics: black, commonmark, markdown, mdformat, pyfmt, python
- Language: Python
- Homepage:
- Size: 52.7 KB
- Stars: 7
- Watchers: 3
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://github.com/hukkinj1/mdformat-black/workflows/Tests/badge.svg?branch=master)]()
[![PyPI version](https://badge.fury.io/py/mdformat-black.svg)]()# 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
```