-
-
Notifications
You must be signed in to change notification settings - Fork 405
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
Syntax highlighting ‘specificity’ lower compared to text editors #260
Comments
Pygments lexers are translated into Chroma lexers automatically, but some constructs cannot be trivially mapped. Different Pygments lexers use this functionality more than others and so some Chroma lexers will be less at parity with Pygments. I've synced the R lexer with the latest from Pygments and it seems to have improved: |
To summarise, Chroma will typically be at parity with Pygments if its lexers are up to date, but for some it will not be and cannot be without manual translation effort. Contributions welcome. |
I see, thank you for the explanation. Indeed, the latest R lexer appears to be improved because while function names were left without a class in my example above, they are now given the correct This falls outside my area of expertise but since it appears to be mostly an issue of selecting appropriate regex patterns to differentiate between various elements, I might be able to contribute—in this instance, should I aim to alter the Pygments R lexer or the Chroma one directly? I've looked at both sources and it appears the automatic translation works well in this instance, though that's just my noob impression. |
Yep this one is entirely automatic. If you update the Pygments lexer I can just sync it into Chroma. That would be ideal for Pygments and Chroma. |
I'm using the built-in Chroma syntax highlighter with Hugo but it seems to lack specificity compared to let's say VSCode or Atom. Consider the following example in JavaScript:
As you can see, the output from Chroma is limited in terms of how many different ‘elements’ it recognises.
This is confirmed by using the Hugo option
pygmentsUseClasses=true
and inspecting the classes it assigns to elements which are highlighted using different colours in text editors but the same once processed by Chroma, for example ‘target’ and ‘offset’ both share theclass="nx"
even though one is a parameter and the other is a method. Another example is ‘this’ and ‘return’ which are bothclass="k"
.This issue is even more striking if you use some other language like R, which looks like there's almost no syntax highlighting at all… :(
Is it possible to set up Chroma to differentiate between such elements and assign them different classes, please?
The text was updated successfully, but these errors were encountered: