blacken-docs
blacken-docs copied to clipboard
Add function and tests for markdown chunks using pygment langs like `{.py` and `{.python` etc
Closes #281
The full regex in the MD_RE variable reads:
(?P<before>^(?P<indent> *)```\s*(\{?\s*)?(\.?)?(python|py|sage|python3|py3|numpy)( .*?)?\n)(?P<code>.*?)(?P<after>^(?P=indent)```\s*$)
If you plug this in to https://regex101.com/, it will give you the following explanation for the 3rd and 4th capture group:
3rd Capturing Group (\{?\s*)?
\{matches the character{with index 12310 (7B16 or 1738) literally (case sensitive)
?matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)\smatches any whitespace character (equivalent to[\r\n\t\f\v ])
*matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)?matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
4th Capturing Group (\.?)?
\.matches the character.with index 4610 (2E16 or 568) literally (case sensitive)
?matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)?matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
This should now meet the needs of both MyST and the Pygment langs used in pymdown-extensions.
Hi @adamchainz, just wondering if there is anything else that I can do to support this PR?
Hi @adamchainz, have you had a chance to look at this one? I'd really like to use this functionality.
Thanks