Subject: | Incorrect error if HTML being inlined has no style blocks |
If the HTML you are trying to inline doesn't have any style blocks, then
CSS::Inliner dies, when instead it should probably just not do anything.
For example, this:
my $inliner = CSS::Inliner->new();
$inliner->read({html => "<html><body><p>blah, blah</p></body></html>"});
$inliner->inlinify;
Dies with this error message: You must instantiate and read in your
content before inlinifying
The attached patch fixes this to just return the original HTML if no CSS
is detected in the document.
Subject: | html_without_css.patch |
--- Inliner.pm.orig 2010-06-29 17:40:54.148895876 -0400
+++ Inliner.pm 2010-06-29 17:43:05.796923500 -0400
@@ -132,7 +132,8 @@
#the remaining html tree has no style block(s) now
my $style = $self->_get_style({tree_content => $tree->content()});
- #stash the stylesheets
+ #stash the data
+ $self->{html} = $$params{html};
$self->{css} = $style;
return();
@@ -159,10 +160,12 @@
croak "You must instantiate this class in order to properly use it";
}
- unless ($self->{css} && $self->{html_tree}) {
+ unless ($self->{html} && $self->{html_tree}) {
croak "You must instantiate and read in your content before inlinifying";
}
+ return $self->{html} unless $self->{css};
+
#parse and store the stylesheet as a hash object
my $css = CSS::Tiny->read_string($self->{css});