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

CSS syntax highlighter #89

Open
scripthunter7 opened this issue May 2, 2023 · 4 comments
Open

CSS syntax highlighter #89

scripthunter7 opened this issue May 2, 2023 · 4 comments
Labels
feature request Request to introduce a new feature T: syntax highlighter The issue is related to the syntax highlighting

Comments

@scripthunter7
Copy link
Member

scripthunter7 commented May 2, 2023

A lot of adblock filter rules use CSS, so we should consider implementing a good CSS highlighter according to our goals (this doesn't necessarily mean full CSS support, e.g. we don't have to support comments).

The benefits of this are:

  • Make CSS-based cosmetic rules much more transparent
    • it improves maintainability
    • it makes the rules clearer for those who don't have much experience in writing rules
  • Many incorrect selectors can be marked as invalid even at the highlighter level

Because of "Extended CSS syntax", we should definitely think about creating our own highlighter, rather than integrating an existing CSS highlighter. In addition, this will ensure consistent results, since VSCode doesn't use the same CSS scope as GitHub.

I started implementing this earlier (last year), here is a demo of what it would look like:

image

In the case of CSS injection rules, at-rules and declaration block should also be handled, but the development can be done step-by-step, so e.g. in the first round, we only implement the CSS selectors for element hiding rules.

Reference:

@scripthunter7 scripthunter7 added the feature request Request to introduce a new feature label May 2, 2023
@scripthunter7 scripthunter7 changed the title Syntax highlighter for CSS selectors CSS syntax highlighter May 2, 2023
@DandelionSprout
Copy link
Member

While I'm all in favour of colourful stuff (which was the main reason I got involved in GitHub Linguist stuff in the first place), I suspect the colours in the screenshot may be a bit overkill. 😅 I'd at least have avoided the green colouring.

@scripthunter7
Copy link
Member Author

This is just a test version, but it follows the default CSS color scheme almost completely

@ameshkov
Copy link
Member

ameshkov commented Jun 8, 2023

Generally, in VSCode it's up to choose you which colors will be used for highlighting.

The task of a highlighter is to define what "type" the token belongs to.

@scripthunter7
Copy link
Member Author

I'll copy my answer from Slack here as well

Based on these regexps (TMLanguage file - which uses Oniguruma compatible regexps), the editor (VSCode / GitHub UI) tokenizes the code and, depending on the color scheme used by the editor, assigns different colors to each token. So, I don't assign a concrete color to certain parts of the code, but specify a token name, and the editor does the coloring. The coloring looks different with the default VSCode theme, or with the VSCode GitHub theme. You can try this tool:
https://novalightshow.netlify.app/
Specify the TMLanguage in the left panel, and the source code (filter list) in the right panel. This is the closest thing to GitHub Linguist, a kind of demo tool (if I remember correctly, GitHub is also planning a demo/preview tool, but they haven't started it yet)

@scripthunter7 scripthunter7 added the T: syntax highlighter The issue is related to the syntax highlighting label Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request to introduce a new feature T: syntax highlighter The issue is related to the syntax highlighting
Projects
None yet
Development

No branches or pull requests

3 participants