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

Syntax highlighting ‘specificity’ lower compared to text editors #260

Closed
lifepeer opened this issue Jul 15, 2019 · 4 comments
Closed

Comments

@lifepeer
Copy link

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:

ggdf

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 the class="nx" even though one is a parameter and the other is a method. Another example is ‘this’ and ‘return’ which are both class="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… :(

hfgdh

Is it possible to set up Chroma to differentiate between such elements and assign them different classes, please?

@alecthomas
Copy link
Owner

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:

image

@alecthomas
Copy link
Owner

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.

@lifepeer
Copy link
Author

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 nf class according to the demo at Pygments which reflects your screenshot.

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.

@alecthomas
Copy link
Owner

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.

mrsdizzie pushed a commit to mrsdizzie/chroma that referenced this issue Jul 15, 2020
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

No branches or pull requests

2 participants