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

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

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.

src/blacken_docs/__init__.py Show resolved Hide resolved
@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