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

Fix: Add whitespace normalization for Pygments 2.19 compatibility #3620

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jasur-py
Copy link

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

Fix test failures occurring after Pygments 2.19 upgrade by adding whitespace normalization for ANSI-colored text comparisons.

##Changes:

  • Added normalize_ansi_whitespace() utility function in tests/test_utils.py
  • Updated failing tests to use normalized whitespace comparison
  • Fixed tests: test_inline_code, test_blank_lines, test_python_render_simple_indent_guides.

Tests added are showing all tests passing [100%].

Screenshot 2025-01-25 at 8 26 35 PM

Fixes #3612

@TomJGooding
Copy link
Contributor

TomJGooding commented Jan 30, 2025

I'm not a maintainer, but could you help clarify why this is needed after upgrading Pygments?

There's a few other pull requests relating to the same issue, but this seems to address the root cause. I just don't understand why whitespace is now handled differently?

@jasur-py
Copy link
Author

I'm not a maintainer, but could you help clarify why this is needed after upgrading Pygments?

There's a few other pull requests relating to the same issue, but this seems to address the root cause. I just don't understand why whitespace is now handled differently?

In this version 2.19 changed how it handles spaces in syntax highlighting, specifically around code elements like keywords and punctuation. The actual highlighting still works correctly, but the spaces are just formatted little differently.
Instead of trying to match Pygments specific spacing (which can change again in the future versions), this solution normalizes the white space when comparing in test. This lets verification that the syntax highlighting is correct about spacing. Rich works properly with the current Pygments version. i hope i could explain.

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.

[BUG] Test failures with pygments 2.19
2 participants