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.9.1
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
Hashes for blacken_docs-1.9.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1ea11e8e25f1c14e28de8cc95e82d8ea8a48de9a4acb469a89e1fe9a4090dfb |
|
MD5 | c18e023f1638e54303aec8d0a7bbf3bf |
|
BLAKE2b-256 | 9a4a2d96374891dc8f46069a577e319c2de5a8363998a880093b9a07b8332436 |