blacken-docs
blacken-docs copied to clipboard
support for orgmode
Org mode (via org babel) allows to include python source blocks. The python code can be edited right away in org mode, but it's a bit of pain to call blacken every time on each code block. (It must be doable in elisp, but for the moment I don't know how to do that). It's much more handy to run blacken-docs on the org file itself.
I don't quite know what to do with the failed checks. In my second to last commit, I repaired the message of pre-commit, namely the long string. For the rest all works on my machine.
That is a messy example, which I also missed.
The problem is that in org mode the noweb references in python code are
written like this: <
For the moment I don't have a generic solution to tackle your example.
BTW, I apple the hack to my org files, and it works really well. But I don't write << 5 >> in my code :-)
On Fri, 19 Aug 2022 at 19:21, Anthony Sottile @.***> wrote:
@.**** commented on this pull request.
In blacken_docs.py https://github.com/asottile/blacken-docs/pull/168#discussion_r950416002:
@@ -178,6 +184,15 @@ def _latex_match(match: Match[str]) -> str: code = textwrap.indent(code, match['indent']) return f'{match["before"]}{code}{match["after"]}'
- def _orgmode_match(match: Match[str]) -> str:
code = textwrap.dedent(match['code'])code = re.sub(r'( *<<.*>>)', r'#\1', code)this hack still isn't going to work -- this is valid code:
x = ( y << 5 >> 1 )
— Reply to this email directly, view it on GitHub https://github.com/asottile/blacken-docs/pull/168#pullrequestreview-1079136395, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM266OJBZ45DTX2IXRU26LVZ67BBANCNFSM5YH3ZNQQ . You are receiving this because you authored the thread.Message ID: @.***>