Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Adblock/AdGuard/uBlock filters grammarNew to Visual Studio Code? Get it now.
Adblock/AdGuard/uBlock filters grammar

Adblock/AdGuard/uBlock filters grammar

AdGuard

adguard.com
|
2,322 installs
| (2) | Free
VS code extension that adds support for ad blocking rules syntax.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

 

AGLint

Adblock Language support for VSCode.

Supported syntaxes:

AdGuard | uBlock Origin | AdBlock | Adblock Plus

VSCode Marketplace Version VSCode Marketplace Downloads VSCode Marketplace Rating License Open GitHub Issues Open GitHub Pull Requests

Table of Contents:

  • Introduction
    • Features
      • Syntax highlighting
      • Adblock rule linter
      • GitHub Linguist support
    • Ideas & Questions
    • Reporting Issues
    • Contributing
    • License
    • References

Introduction

This extension adds support for AdGuard, uBlock Origin and Adblock Plus syntaxes to Visual Studio Code, so you can write adblock rules in a convenient way. It also provides a linter to check your rules for errors.

We recommend using this extension if you are working with adblock rules. It is available on VSCode Marketplace.

GitHub Linguist support is also available, so you can highlight your adblock rules in GitHub repositories. See GitHub Linguist support for more details. Quick example:

! This is an example rule
example.org##.banner
||example.net/script.js$script,third-party,domain=example.com

Features

In this section we will describe the main features of this extension.

Syntax highlighting

Syntax highlighting is available for AdGuard, uBlock Origin and Adblock Plus syntaxes. Nowadays it is unimaginable to work with code without highlighting, which helps you to distinguish different parts of the code and makes it easier to read.

Adblock rule linter

We integrated AGLint into this extension, that makes it able to check your rules for various issues, such as invalid syntax, invalid domains, invalid / incompatible CSS selectors, unknown / incompatible scriptlets, bad practices, etc. For more information about AGLint, please refer to its repository.

:warning: Please note that the linter is under active development, so it may not work properly for some rules. If you find any issues, please report them here. We look forward to your feedback, your help is very important to us!

GitHub Linguist support

GitHub supports adblock syntax officially via the Linguist library. Our extension provides a TMLanguage file, which is used by Linguist to highlight adblock rules (VSCode highlight also based on this file). This means that if you have a repository with adblock rules, GitHub can highlight your .txt files, if the following conditions are met:

  • If a *.txt file begins with an adblock agent (such as [Adblock Plus 2.0], [AdGuard], [uBlock Origin], [Adblock Plus 2.0; AdGuard], etc.), then it will be highlighted as an adblock file automatically. You can find the detection heuristics here.
  • In any other cases, you can override the language classification by adding the following lines to .gitattributes file:
    # Override classification for *.txt files, so they are highlighted as adblock files.
    # - This example will match all *.txt files in the repository, but you can
    #   customize path(s) to match only specific files, such as /filters/*.txt
    #   or /filters/*.adblock. See https://git-scm.com/docs/gitattributes for more details.
    # - By default, Adblock language doesn't show up in the repository's language statistics,
    #   but adding linguist-detectable will resolve this, so it is recommended to add it.
    *.txt linguist-language=AdBlock linguist-detectable
    
    You can find more information about overriding language classification here.

In addition, adblock code blocks can be inserted in markdown files and comments according to the following pattern:

```adblock
! Example rule
example.org##.banner
```

will be rendered as:

! Example rule
example.org##.banner

Ideas & Questions

If you have any questions or ideas for new features, please open an issue or a discussion. We will be happy to discuss it with you.

Reporting Issues

If you found a bug or have a feature request, please report it here. Please make sure to include as much information as possible, including screenshots or example rules.

Please note that the highlighter issues on GitHub will not be fixed immediately when we update the TMLanguage in this repository. GitHub's highlighter is only updated after Linguist releases. This process happens roughly every quarter. Before release, Linguist maintainers will update all integrated TMLanguage to the latest version. You can find more information about Linguist's release process here.

Contributing

If you want to contribute to this project, please read the CONTRIBUTING file.

License

This extension is licensed under the MIT License. See the LICENSE file for details.

References

Here are some useful links to help you write adblock rules. This list is not exhaustive, so if you know any other useful resources, please let us know.

  • Basic documentations for each adblock syntax:
    • ADG How to create your own ad filters: https://adguard.com/kb/general/ad-filtering/create-own-filters/
    • uBO Static filter syntax: https://github.com/gorhill/uBlock/wiki/Static-filter-syntax
    • ABP How to write filters: https://help.eyeo.com/adblockplus/how-to-write-filters
  • Extended CSS:
    • MDN CSS selectors: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors
    • ADG Extended CSS capabilities: https://github.com/AdguardTeam/ExtendedCss/blob/master/README.md#extended-capabilities
    • uBO Procedural cosmetic filters: https://github.com/gorhill/uBlock/wiki/Procedural-cosmetic-filters
    • ABP Extended CSS selectors: https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide-emulation
  • Scriptlets:
    • ADG scriptlets: https://github.com/AdguardTeam/Scriptlets/blob/master/wiki/about-scriptlets.md#scriptlets
    • uBO scriptlets: https://github.com/gorhill/uBlock/wiki/Resources-Library#available-general-purpose-scriptlets
    • ABP snippets: https://help.eyeo.com/adblockplus/snippet-filters-tutorial#snippets-ref
  • Third party libraries:
    • CSSTree: https://github.com/csstree/csstree/tree/master/docs
  • AdGuard's compatibility tables:
    • https://github.com/AdguardTeam/Scriptlets/blob/master/wiki/compatibility-table.md
  • Contact us
  • Jobs
  • Privacy
  • Terms of use
  • Trademarks
© 2023 Microsoft