blacken-docs icon indicating copy to clipboard operation
blacken-docs copied to clipboard

Add function and tests for markdown chunks using pygment langs like `{.py` and `{.python` etc

Open chrimaho opened this issue 2 years ago • 3 comments

Closes #281

chrimaho avatar Sep 04 '23 23:09 chrimaho

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)
  • \s matches 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.

chrimaho avatar Sep 11 '23 22:09 chrimaho

Hi @adamchainz, just wondering if there is anything else that I can do to support this PR?

chrimaho avatar Nov 02 '23 20:11 chrimaho

Hi @adamchainz, have you had a chance to look at this one? I'd really like to use this functionality.
Thanks

chrimaho avatar Dec 22 '23 00:12 chrimaho