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
[tsx] TypescriptLexer does not correctly support tsx #1815
Comments
|
I'm confused. Why is there a lexer for JSX listed here? https://pygments.org/docs/lexers/#lexers-for-jsx-react I'm trying to create a TSX code block with Manim, which uses pygments. It says over there that any lexer listed https://pygments.org/docs/lexers would be supported. But it's not recognizing So the Manim docs are wrong, or am I missing something? |
The JSX lexer exists in the latest source code but not in a release yet. |
What kind of timeline for a release? Right now I'm trying to get ChatGPT to write and register a lexer for me and I have no idea what I'm doing, lol |
Well thanks for mentioning the source code containing the JSX lexer. That really helped, because ChatGPT was giving me a lot of nonsense. Getting this released will be nice, but it would be nice to have a TSX lexer too, not just JSX. I copied the code from here https://github.com/pygments/pygments/blob/master/pygments/lexers/jsx.py And imported the TypeScriptLexer instead of the JavascriptLexer, and updated names to tsx instead of jsx And I did something probably hacky, but add this at the bottom of my python script (called # Adjust the module name for registration
module_name = __name__ if __name__ != "__main__" else "custom_lexers"
# Registering the lexer with pygments
lexers.LEXERS["TSXLexer"] = (module_name, "TSX", ("tsx",), ("*.tsx",), ("text/x-tsx",)) And then I just imported this at the top of my Manim script: It's working for me. |
Very definitely hacky. Why don't you just install the latest master version of Pygments? It should be as easy as |
I didn't know you could do that. Thanks. Basically Week 2 for me using Python. But also I need TSX, not just JSX. |
Sorry, we don't have that at the moment. To do it the proper way instead of that horrible hack, you'd write a plugin. https://pygments.org/docs/plugins/ (You might also find some useful info in this recent issue, I haven't had the time to improve the docs yet: #2550.) |
Currently
tsx
is supposed to be supported via theTypescriptLexer
, however there are several issues when parsing tsx files. I'd suggest removing that support for theTypescriptLexer
, just like it is for theJavascriptLexer
, which does not supportjsx
. Additionally prioritizingtsx
andjsx
support would be highly appreciated, so that we don't need to rely on external packages like https://github.com/richardbann/pygments-lexer-babylon. (See issues #868 and #709.)Errors
Token.Name
orToken.Keyword
<
,>
, and/
are parsed as operatorsBelow is a comparison of the same markup parsed with the html and typescript parser.
HTML
pygments tokens
TSX
pygments tokens
The text was updated successfully, but these errors were encountered: