Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Python code in docs (ReST, markdown etc) #294

Closed
blueyed opened this issue Jun 2, 2018 · 6 comments
Closed

Handle Python code in docs (ReST, markdown etc) #294

blueyed opened this issue Jun 2, 2018 · 6 comments
Labels
C: parser How we parse code. Or fail to parse it. help wanted Extra attention is needed T: enhancement New feature or request

Comments

@blueyed
Copy link
Contributor

blueyed commented Jun 2, 2018

It would be nice if black would also handle Python code blocks in documentation files (reStructuredText, markdown etc).

(via pytest-dev/pytest#3525 (comment))

@asottile
Copy link
Contributor

asottile commented Jun 2, 2018

hah, I had the same idea: #292

@blueyed
Copy link
Contributor Author

blueyed commented Jun 2, 2018

Heh..
Your issue seems to be a bit broader, and would be possible probably already, given that you could extract code blocks, run black on them and then replace them (kind of an API usage).

What I had in mind would be that black could be just run on documentation files, and would handle all code blocks in there.

Let's wait for some feedback from maintainer(s).

@ambv
Copy link
Collaborator

ambv commented Jun 2, 2018

Sounds interesting, it would require a lot more dependencies to be added to Black though to enable parsing Markdown, ReST, and so on. I'll leave this open as I am not opposed to the idea. However, there are more urgent things we need to implement/fix before we can think about this.

@asottile
Copy link
Contributor

asottile commented Jun 2, 2018

I'm going to take a stab at implementing this in a separate project, maybe at some point it could be merged back into core

@asottile
Copy link
Contributor

asottile commented Jun 3, 2018

It lives! https://github.com/asottile/blacken-docs

Here's an example PR of what it can do: pytest-dev/pytest#3528

gaborbernat pushed a commit to tox-dev/tox that referenced this issue Jun 3, 2018
Hi friends, I made a terrific (terrible? terrifying?) thing.

I needed one manual `,` addition to the `setup.py` example so it could be parsed -- otherwise this is fully automated!

Using the new thing I made today: https://github.com/asottile/blacken-docs

Heavily inspired by pytest-dev/pytest#3525.  See also psf/black#292, psf/black#294.
@ambv ambv added the T: enhancement New feature or request label Jun 5, 2018
@ambv ambv added the help wanted Extra attention is needed label Aug 17, 2018
@JelleZijlstra JelleZijlstra added the C: parser How we parse code. Or fail to parse it. label May 30, 2021
@hauntsaninja
Copy link
Collaborator

Thank you! Given the existence of tools like https://github.com/adamchainz/blacken-docs and https://github.com/hukkin/mdformat-black, I don't think we should include this in Black proper. The long tail of formats is best dealt with by the ecosystem and we should do things like #779 to help support the ecosystem build on Black.

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: parser How we parse code. Or fail to parse it. help wanted Extra attention is needed T: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants