From c1750f6bdcdcbe592a867e4d695f29e58c2080d6 Mon Sep 17 00:00:00 2001 From: sunnavy Date: Wed, 3 Dec 2025 16:47:25 -0500 Subject: [PATCH] Support for ignoring specified CSS selectors This feature was initially designed to handle problematic Outlook emails, which can contain thousands of empty
 tags that interfere with
processing.
---
 lib/CSS/Inliner.pm | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/CSS/Inliner.pm b/lib/CSS/Inliner.pm
index 42aaa46..d0760d5 100755
--- a/lib/CSS/Inliner.pm
+++ b/lib/CSS/Inliner.pm
@@ -43,7 +43,7 @@ sponsoring entity, MailerMailer LLC, has been sold to j2 Global.
 =cut
 
 BEGIN {
-  my $members = ['stylesheet','css','html','html_tree','query','strip_attrs','relaxed','leave_style','warns_as_errors','content_warnings','agent','fixlatin','encode_entities','ignore_style_type_attr'];
+  my $members = ['stylesheet','css','html','html_tree','query','strip_attrs','relaxed','leave_style','warns_as_errors','content_warnings','agent','fixlatin','encode_entities','ignore_style_type_attr','ignore_selectors'];
 
   #generate all the getter/setter we need
   foreach my $member (@{$members}) {
@@ -84,6 +84,8 @@ ignore_style_type_attr - (optional) Ignore the deprecated type attribute of "sty
 
 NOTE: This argument is not compatible with passing an html_tree.
 
+ignore_selectors - (optional) Specifies a list of CSS selectors. Any style rules targeting these selectors will be ignored.
+
 agent - (optional) Pass in a string containing a preferred user-agent, overrides the internal default provided by the module for handling remote documents
 
 =cut
@@ -120,6 +122,7 @@ sub new {
     fixlatin => eval { require Encoding::FixLatin; return 1; } ? 1 : 0,
     encode_entities => (defined($$params{encode_entities}) && $$params{encode_entities}) ? 1 : 0,
     ignore_style_type_attr => (defined($$params{ignore_style_type_attr}) && $$params{ignore_style_type_attr}) ? 1 : 0,
+    ignore_selectors => $$params{ignore_selectors},
   };
 
   bless $self, $class;
@@ -435,6 +438,7 @@ sub inlinify {
       next unless exists $$entry{selector} && $$entry{declarations};
 
       my $selector = $$entry{selector};
+      next if $self->_ignore_selectors && grep { $selector eq $_ } @{$self->_ignore_selectors};
       my $declarations = $$entry{declarations};
 
       #skip over the following pseudo selectors, these particular ones are not inlineable