Run `black` on python code blocks in documentation files
Project description
blacken-docs
Run black on python code blocks in documentation files.
install
pip install blacken-docs
usage
blacken-docs provides a single executable (blacken-docs) which will modify
.rst / .md / .tex files in place.
It currently supports the following black
options:
-l/--line-length-t/--target-version-S/--skip-string-normalization
Following additional parameters can be used:
-E/--skip-errors
blacken-docs will format code in the following block types:
(markdown)
```python
def hello():
print("hello world")
```
(rst)
.. code-block:: python
def hello():
print("hello world")
(rst pycon)
.. code-block:: pycon
>>> def hello():
... print("hello world")
...
(latex)
\begin{minted}{python}
def hello():
print("hello world")
\end{minted}
(latex with pythontex)
\begin{pycode}
def hello():
print("hello world")
\end{pycode}
(markdown/rst in python docstrings)
def f():
"""docstring here
.. code-block:: python
print("hello world")
```python
print("hello world")
```
"""
usage with pre-commit
See pre-commit for instructions
Sample .pre-commit-config.yaml:
- repo: https://github.com/asottile/blacken-docs
rev: v1.10.0
hooks:
- id: blacken-docs
additional_dependencies: [black==...]
Since black is currently a moving target, it is suggested to pin black
to a specific version using additional_dependencies.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file blacken_docs-1.10.0.tar.gz.
File metadata
- Download URL: blacken_docs-1.10.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2121c95bf2f8a3ebb3110776d276f850f63b8e5753773ba2b4d0f415d862f23
|
|
| MD5 |
7d6601631f83bd1f995cb5f0f013b56d
|
|
| BLAKE2b-256 |
803b8168bea0a33d9afc0d3a147ea85c77bece52a41723351e82ddd7de33e7a1
|
File details
Details for the file blacken_docs-1.10.0-py2.py3-none-any.whl.
File metadata
- Download URL: blacken_docs-1.10.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
149197a0b17e83121fc10aca9eda1417728fdccebde930a6722f97d87ed30f4b
|
|
| MD5 |
66854406ed513e684ebe8ecde04e6178
|
|
| BLAKE2b-256 |
51313c3623a6b042a0a02486cb939e625506cc926767bf37cb42ee1bd6d0b861
|