- Timestamp:
- 06/12/08 23:27:40 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/HTMLFilter/DoCoMoCSS.pm
r13049 r13739 4 4 use CSS::Tiny; 5 5 use XML::LibXML; 6 use HTML::Selector::XPath ;6 use HTML::Selector::XPath qw(selector_to_xpath); 7 7 use App::Mobirc::Util; 8 8 use Encode; 9 9 use Path::Class; 10 use XML::LibXML::XPathContext; 10 11 11 12 # some code copied from HTML::DoCoMoCSS … … 14 15 15 16 DEBUG "FILTER DOCOMO CSS"; 16 return ($c, $content) unless $c->req->mobile_agent->is_docomo;17 # return ($c, $content) unless $c->req->mobile_agent->is_docomo; 17 18 18 19 # escape Numeric character reference. … … 23 24 my $css = CSS::Tiny->read_string($self->css_text($global_context)); 24 25 my $doc = eval { XML::LibXML->new->parse_string($content); }; 25 $@ and return ($c, $pict_unescape->()); 26 if (my $e = $@) { 27 return ($c, $pict_unescape->()); 28 } 29 my $xc = XML::LibXML::XPathContext->new($doc); 30 my $root = $doc->documentElement(); 31 my $namespace = $root->getAttribute('xmlns'); 32 my $namespace_prefix = ''; 33 if ($namespace) { 34 # xhtml 35 $xc->registerNs( 'x', $namespace ); 36 $namespace_prefix = 'x:'; 37 } 26 38 27 39 # apply inline css 28 40 while (my($selector, $style) = each %{ $css }) { 29 41 my $style_stringify = join ';', map { "$_:$style->{$_}" } keys %{ $style }; 30 for my $element ( $doc->findnodes( HTML::Selector::XPath::selector_to_xpath($selector) ) ) { 42 my $xpath = selector_to_xpath($selector); 43 $xpath =~ s{^//}{//$namespace_prefix}; 44 for my $element ( $xc->findnodes( $xpath ) ) { 31 45 my $style_attr = $element->getAttribute('style'); 32 46 $style_attr = (!$style_attr) ? $style_stringify : (join ";", ($style_attr, $style_stringify));
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)