E[attr~="foo"]
[catagits/HTML-Zoom.git] / lib / HTML / Zoom / SelectorParser.pm
index 007b250..096eb3e 100644 (file)
@@ -18,6 +18,38 @@ sub _raw_parse_simple_selector {
     /\G\*/gc and
       return sub { 1 };
 
+     # 'el[attr~="foo"]
+
+    /\G$sel_re\[$sel_re~="$sel_re"\]/gc and
+      return do {
+        my $name = $1;
+        my $attr = $2;
+        my $val = $3;
+        sub {
+          if (
+            $_[0]->{name} && $_[0]->{name} eq $name and
+            $_[0]->{attrs}{$attr}
+          ) {
+            my %vals = map { $_ => 1 } split /\s+/, $_[0]->{attrs}{$attr};
+            return $vals{$val}
+          }
+          return undef
+        }
+      };
+
+     # 'el[attr="foo"]
+
+    /\G$sel_re\[$sel_re="$sel_re"\]/gc and
+      return do {
+        my $name = $1;
+        my $attr = $2;
+        my $val = $3;
+        sub {
+           $_[0]->{name} && $_[0]->{name} eq $name and
+           $_[0]->{attrs}{$attr} && $_[0]->{attrs}{$attr} eq $val
+        }
+      };
+
     # 'element' - match on tag name
 
     /\G$sel_re/gc and
@@ -58,6 +90,18 @@ sub _raw_parse_simple_selector {
         }
       };
 
+    # 'el#id' - element + id
+
+    /\G$sel_re#$sel_re/gc and
+      return do {
+        my $id = $1;
+        my $name = $2;
+        sub {
+           $_[0]->{name} && $_[0]->{name} eq $name and
+           $_[0]->{attrs}{id} && $_[0]->{attrs}{id} eq $id
+        }
+      };
+
     confess "Couldn't parse $_ as starting with simple selector";
   }
 }