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

Allow printing lists as JSON. #1890

Merged
merged 4 commits into from
Sep 11, 2021
Merged

Allow printing lists as JSON. #1890

merged 4 commits into from
Sep 11, 2021

Conversation

Anteru
Copy link
Collaborator

@Anteru Anteru commented Sep 4, 2021

Fixes #1437

arg_set.discard('L')
arg_set.discard('json')

# json can be only used with L, so we remove L, and check if there is
Copy link
Member

Choose a reason for hiding this comment

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

comment isn't accurate anymore

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, thanks!

for fullname, names, exts, _ in get_all_lexers():
info[fullname] = {
'names': names,
'extensions': exts
Copy link
Member

Choose a reason for hiding this comment

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

This is usually called filenames since it's a glob matching the whole filename.

Any reason you're not returning the mimetypes (third element)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I compared with the current output and it wasn't printed there, so I omitted it here as well, but I have no feelings about adding it to the JSON output :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to filenames, and added mimetypes

info = {}
for fullname, names, exts, _ in get_all_lexers():
info[fullname] = {
'names': names,
Copy link
Member

Choose a reason for hiding this comment

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

let's call this 'aliases'.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Copy link

@legoktm legoktm left a comment

Choose a reason for hiding this comment

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

I tested this and it provides all the functionality I was looking for, thank you for working on it!

}
result['styles'] = info

json.dump(result, sys.stdout, indent=4)
Copy link

Choose a reason for hiding this comment

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

minor: Since the point of JSON is to be machine readable, I don't think you need to specify indent=4 to make it more human readable. I think most people who want to look at the JSON output would know how to run it through a pretty printer like jq.

Copy link
Collaborator Author

@Anteru Anteru Sep 8, 2021

Choose a reason for hiding this comment

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

Oh absolutely, this was mostly for my debugging sanity :)

@Anteru
Copy link
Collaborator Author

Anteru commented Sep 8, 2021

I tested this and it provides all the functionality I was looking for, thank you for working on it!

Thanks a lot for testing & confirming this works!

@Anteru Anteru merged commit 0f6672e into master Sep 11, 2021
@Anteru Anteru deleted the fix/1437 branch September 11, 2021 20:28
@Anteru Anteru added this to the 2.11.0 milestone Sep 12, 2021
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.

Have pygmentize output as JSON instead
3 participants