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 highlighting issue when printing JSON that isn't indented #2038

Merged
merged 8 commits into from
Mar 8, 2022

Conversation

darrenburns
Copy link
Member

@darrenburns darrenburns commented Mar 8, 2022

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

Previously the JSONHighlighter would do two passes with Text.highlight - the second pass would highlight JSON keys.

I've got rid of the second regex for the 2nd Text.highlight pass, and replaced it with a regex which captures the spans of strings, followed by some manual processing to determine whether they're keys or not. If the string is a key, we append the json.key Span.

image

image

image

image

Previously:

image

Closes #2027

@codecov-commenter
Copy link

codecov-commenter commented Mar 8, 2022

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.78%. Comparing base (862416a) to head (94a1074).
Report is 1239 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2038      +/-   ##
==========================================
+ Coverage   99.54%   99.78%   +0.24%     
==========================================
  Files          73       71       -2     
  Lines        7294     7109     -185     
==========================================
- Hits         7261     7094     -167     
+ Misses         33       15      -18     
Flag Coverage Δ
unittests 99.78% <100.00%> (+0.24%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@darrenburns darrenburns marked this pull request as ready for review March 8, 2022 15:48
Copy link
Collaborator

@willmcgugan willmcgugan left a comment

Choose a reason for hiding this comment

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

Just a couple of requests, as discussed...

rich/highlighter.py Outdated Show resolved Hide resolved
rich/highlighter.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@willmcgugan willmcgugan left a comment

Choose a reason for hiding this comment

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

LGTM

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] rich.print_json() produces incorrect syntax highlighting with indent=None
3 participants