Navigation Menu

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

Codecov Report

Merging #2038 (93e584c) into master (75f4637) will decrease coverage by 0.02%.
The diff coverage is 96.29%.

❗ Current head 93e584c differs from pull request most recent head 9e3ae26. Consider uploading reports for the commit 9e3ae26 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2038      +/-   ##
==========================================
- Coverage   99.81%   99.78%   -0.03%     
==========================================
  Files          71       71              
  Lines        7058     7107      +49     
==========================================
+ Hits         7045     7092      +47     
- Misses         13       15       +2     
Flag Coverage Δ
unittests 99.78% <96.29%> (-0.03%) ⬇️

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

Impacted Files Coverage Δ
rich/console.py 100.00% <ø> (ø)
rich/pretty.py 99.21% <93.93%> (-0.50%) ⬇️
rich/__init__.py 100.00% <100.00%> (ø)
rich/_inspect.py 100.00% <100.00%> (ø)
rich/highlighter.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9b99ad...9e3ae26. Read the comment docs.

@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