AdguardTeam / VscodeAdblockSyntax

Comprehensive extension to manage Adblock Syntax in VSCode: syntax highlighter, linter and much more. Available on the VSCode Marketplace.
https://marketplace.visualstudio.com/items?itemName=adguard.adblock
MIT License
74 stars 8 forks source link

CSS syntax highlighter #89

Open scripthunter7 opened 1 year ago

scripthunter7 commented 1 year ago

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:

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:

DandelionSprout commented 1 year ago

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 commented 1 year ago

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

ameshkov commented 1 year ago

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 commented 1 year ago

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)