Skip to content

Commit

Permalink
Merge pull request #49 from scripthunter7/master
Browse files Browse the repository at this point in the history
Adblock agent support, modifier separator fix
  • Loading branch information
ameshkov authored Aug 15, 2022
2 parents 6e56ca1 + 1c8db08 commit de372c9
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 0.0.27

- Added support for adblock agents
- Fix redundant modifier detection: #25

## 0.0.26

- Added support for cosmetic rules modifiers: #47
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "adblock",
"displayName": "Adblock/AdGuard/uBlock filters grammar",
"description": "VS code extension that adds support for ad blocking rules syntax.",
"version": "0.0.26",
"version": "0.0.27",
"publisher": "adguard",
"icon": "images/icon.png",
"engines": {
Expand Down
58 changes: 53 additions & 5 deletions syntaxes/adblock.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "Adblock",
"patterns": [
{
"include": "#adblockAgent"
},
{
"include": "#preprocessor"
},
Expand Down Expand Up @@ -37,6 +40,51 @@
}
],
"repository": {
"adblockAgent": {
"patterns": [
{
"match": "^(\\[)([^\\]]+)(\\])\\s*$",
"captures": {
"1": {
"name": "punctuation.definition.array.start.ablock.agent"
},
"2": {
"patterns": [
{
"include": "#adblockData"
},
{
"match": ";",
"name": "punctuation.separator"
},
{
"name": "invalid.illegal",
"match": ".*"
}
]
},
"3": {
"name": "punctuation.definition.array.end.ablock.agent"
}
}
}
]
},
"adblockData": {
"patterns": [
{
"match": "(?:\\s*)([Aa]d[Bb]lock(?:\\s[Pp]lus)?|u[Bb]lock(?:\\s[Oo]rigin)?|[Aa]d[Gg]uard)(?:\\s+(\\d+(?:\\.\\d+)*+\\+?))?(?:\\s*)",
"captures": {
"1": {
"name": "constant.language.agent.adblocker.name"
},
"2": {
"name": "constant.numeric.decimal"
}
}
}
]
},
"preprocessor": {
"patterns": [
{
Expand Down Expand Up @@ -142,10 +190,6 @@
"name": "comment.line",
"match": "^!.*"
},
{
"name": "comment.line.header",
"match": "^\\[Adblock.*"
},
{
"name": "comment.line.batch-style",
"match": "^# .*"
Expand Down Expand Up @@ -405,7 +449,7 @@
"basicRules": {
"patterns": [
{
"match": "^(.+?)((\\$)(.*))?$",
"match": "^(.+?)((\\$(?!\\/))(.*))?$",
"captures": {
"1": {
"patterns": [
Expand Down Expand Up @@ -658,6 +702,10 @@
{
"match": ",",
"name": "punctuation.definition.adblock"
},
{
"match": "\\$",
"name": "invalid.illegal.redundant.modifier.separator"
}
]
},
Expand Down
10 changes: 9 additions & 1 deletion test_rules.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[Adblock Plus 3.1; AdGuard]
[AdGuard; Invalid Name 2.0]
!
! Test rules for the syntax highlighter
!
Expand Down Expand Up @@ -308,4 +310,10 @@ $removeheader=location,domain=zannn.top|innal.top
!
! Cosmetic rules modifiers, invalid modifiers
!
[$randommodifier=test]##banner
[$randommodifier=test]##banner

! https://github.com/ameshkov/VscodeAdblockSyntax/issues/25
/^https:\/\/.*?\/v2\/0\/[a-zA-Z0-9_-]{30,}$/$third-party,script,$domain=~example.org
||example.com/example.js^$script,$third-party,$domain=example.org
||example.com/example.js^$script,$~third-party,$domain=example.org
||example.com/example.js^$script,third-party,$domain=example.org|example.net

0 comments on commit de372c9

Please sign in to comment.