Changeset 1786

Show
Ignore:
Timestamp:
02/28/06 17:35:14
Author:
miyagawa
Message:

support <base>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • HTML-ResolveLink/trunk/lib/HTML/ResolveLink.pm

    r1785 r1786  
    2828sub _start_tag { 
    2929    my($self, $tagname, $attr, $attrseq, $text) = @_; 
     30 
     31    if ($tagname eq 'base' && defined $attr->{href}) { 
     32        $self->{resolvelink_base} = $attr->{href}; 
     33    } 
    3034 
    3135    my $base = $self->{resolvelink_base}; 
     
    97101 
    98102  my $resolver = HTML::ResolveLink->new( 
    99       base => 'http://www.example.com/', 
     103      base => 'http://www.example.com/foo/bar.html', 
    100104  ); 
    101105  $html = $resolver->resolve($html); 
     
    105109HTML::ResolveLink is a module to rewrite relative links in XHTML or 
    106110HTML into absolute URI. 
     111 
     112For example. when you have 
     113 
     114  <a href="foo.html">foo</a> 
     115  <img src="/bar.gif" /> 
     116 
     117and use C<http://www.example.com/foo/bar> as C<base> URL, you'll get: 
     118 
     119  <a href="http://www.example.com/foo/foo.html">foo</a> 
     120  <img src="http://www.example.com/bar.gif" /> 
     121 
     122If the parser encounters C<< <base> >> tag in HTML, it'll honor that. 
    107123 
    108124=head1 METHODS 
  • HTML-ResolveLink/trunk/t/01_resolve.t

    r1785 r1786  
    11use strict; 
    2 use Test::More 'no_plan'
     2use Test::More tests => 2
    33use HTML::ResolveLink; 
    44 
     
    1313<!-- hello --> 
    1414HTML 
    15     ; 
    1615 
    1716is $html, <<'HTML'; 
     
    2221<!-- hello --> 
    2322HTML 
     23 
     24$html = $resolver->resolve(<<'HTML'); 
     25<base href="http://www.google.com/"> 
     26<a href="baz">foo</a> 
     27<base href="http://www.example.com/"> 
     28<a href="baz">foo</a> 
     29HTML 
     30 
     31is $html, <<'HTML', '<base>'; 
     32<base href="http://www.google.com/"> 
     33<a href="http://www.google.com/baz">foo</a> 
     34<base href="http://www.example.com/"> 
     35<a href="http://www.example.com/baz">foo</a> 
     36HTML 
    2437    ;