Textualize / rich-cli

Rich-cli is a command line toolbox for fancy output in the terminal
https://www.textualize.io
MIT License
3.1k stars 77 forks source link

better support for jsx or adding jsx as a lexer? #50

Closed onlyphantom closed 2 years ago

onlyphantom commented 2 years ago

Syntax highlighting of HTML closing tags in .js files seems to be wrong however, and I understand that this is due to the way Pygment / lexer handles js file more so than rich-cli per-se, but with js libraries such as React being so prevalent nowadays would this be an interesting area of improvement?

Related to that -- maybe we could add a jsx as a lexer as well?

Screenshot from 2022-04-25 13-51-33

Screenshot from 2022-04-25 13-47-29

BD103 commented 2 years ago

Rich-CLI uses Pygments to detect the file type. This means you can install any extension you want that plugs into Pygments. To fix the highlighting issue, install the following package:

$ pip install jsx-lexer

You can then run Rich over a JSX file.

rich-cli-jsx

The file type must be .jsx, the .js lexer will still give issues if you use JSX syntax within it.

If this issue comes up again, I could probably PR an optional dependency to JSX-Lexer along with a suggestion if trying to highlight a JSX file.

onlyphantom commented 2 years ago

Thank you for the quick reply!

I think the suggestion makes a lot of sense. If rich is run on a file with the jsx extension, then raise a message that ask if the user would like to install the optional jsx-lexer?

and I understand that this is due to the way Pygment / lexer handles js file more so than rich-cli per-se

uses Pygments to detect the file type

Anyway -- closing the issue now since, as was my original consideration, it isn't something rich-cli has to be concerned about and the problem lies further upstream.