blacken-docs
blacken-docs copied to clipboard
IPython shell examples
I tend to use IPython shell examples rather than the plain Python console, and I'd like blacken-docs to format them, e.g.
.. code-block:: ipython
- In [1]: print('Hello World')
+ In [1]: print("Hello World")
Hello World
In [2]: print(
- ...: 'Hello World'
+ ...: "Hello World"
...: )
Hello World
Would this be an accepted feature? Happy to give it a shot if so.
if you want to make it work and maintain it sure
The tricky part here is dealing with IPython magics, such as %%timeit, which aren't valid Python syntax
Just bringing up black's IPython magic handler, in case it's useful https://github.com/psf/black/blob/main/src/black/handle_ipynb_magics.py (perhaps it's even possible to do this reusing black.format_cell?)
This may be somewhat redundant, since IPython has the ability to run Black on input lines during execution. It doesn't help with reformatting existing shell sessions but it covers creating them.