Subject: | Custom HTML::TreeBuilder object |
CSS::Inliner uses HTML::TreeBuilder internally to do some of the heavy
lifting when dealing with the HTML. But it creates a vanilla
HTML::TreeBuilder object with just the defaults and HTML::TreeBuilder
has lots of knobs that can be adjusted.
It would be nice if you could pass in an HTML::TreeBuilder object when a
CSS::Inliner object is created which will be used instead. This attached
patch accomplishes that.
Subject: | custom_html_tree.patch |
--- Inliner.pm 2010-01-26 10:44:44.000000000 -0500
+++ Inliner.pm.new 2010-02-25 14:05:22.856646633 -0500
@@ -58,11 +58,12 @@
sub new {
my $this = shift;
my $class = ref($this) || $this;
+ my %args = @_;
my $self = {
css => undef,
html => undef,
- html_tree => undef,
+ html_tree => $args{html_tree} || HTML::TreeBuilder->new(),
};
if (@_) {
@@ -127,7 +128,7 @@
croak "You must pass in hash params that contains html data";
}
- my $tree = new HTML::TreeBuilder();
+ my $tree = $self->{html_tree};
$tree->store_comments(1);
$tree->parse($$params{html});
@@ -138,9 +139,6 @@
#stash the stylesheets
$self->{css} = $style;
- #keep the html tree for later so we don't have to reparse
- $self->{html_tree} = $tree;
-
return();
}