Add support for [attr~="value"] selector (attribute contains word)
[catagits/HTML-Zoom.git] / lib / HTML / Zoom / SelectorParser.pm
index 9bc7bc3..be08175 100644 (file)
@@ -81,6 +81,17 @@ sub _raw_parse_simple_selector {
         }
       };
 
+    # '[attr~=bar]' - match attribute contains word
+    /\G\[$sel_re~=$match_value_re\]/gc and
+      return do {
+        my $attribute = $1;
+        my $value = $2;
+        sub {
+          $_[0]->{attrs}{$attribute}
+          && grep { $_ eq $value } split(' ', $_[0]->{attrs}{$attribute});
+        }
+      };
+
     # '[attr=bar]' - match attributes
     /\G\[$sel_re=$match_value_re\]/gc and
       return do {
@@ -92,7 +103,7 @@ sub _raw_parse_simple_selector {
         }
       };
 
-    # '[attr] - match attribute being present:
+    # '[attr]' - match attribute being present:
     /\G\[$sel_re\]/gc and
       return do {
         my $attribute = $1;