8000 Add function and tests for markdown chunks using pygment langs like `{.py` and `{.python` etc by chrimaho · Pull Request #282 · adamchainz/blacken-docs · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@chrimaho
Copy link
@chrimaho chrimaho commented Sep 4, 2023

Closes #281

Copy link
Owner
@adamchainz adamchainz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s quite a lot of overlap here with #239, the MyST support. I will defer a proper review for now since I want to dive into understanding both formats to understand how to keep things easy to understand.

@chrimaho
Copy link
Author
chrimaho commented Sep 11, 2023

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
Copy link
Author
chrimaho commented Nov 2, 2023

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

@chrimaho

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Markdown fence syntax

2 participants

0