From d8426f37c88c5d980aa93855e40b50c97c282590 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 7 Jan 2009 12:26:40 -0500 Subject: [PATCH] support elements This gets move complicated parsing the html since the body of the element needs to be recorded if there is no title. --- webcheckout | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/webcheckout b/webcheckout index 6df790d..a6ae94f 100755 --- a/webcheckout +++ b/webcheckout @@ -182,15 +182,37 @@ sub parse { my @ret; my $parser=HTML::Parser->new(api_version => 3); + my $abody=undef; + my $aref=undef; $parser->handler(start => sub { my $tagname=shift; my $attr=shift; - return if lc $tagname ne 'link'; return if ! exists $attr->{rel} || lc $attr->{rel} ne 'vcs'; return if ! exists $attr->{href} || ! length $attr->{href}; return if ! exists $attr->{type} || ! length $attr->{type}; + + # need to collect the body of the tag if there is no title + if ($tagname eq "a" && ! exists $attr->{title}) { + $abody=""; + $aref=$attr; + } + push @ret, $attr; }, "tagname, attr"); + $parser->handler(text => sub { + if (defined $aref) { + $abody.=join(" ", @_); + } + }, "text"); + $parser->handler(end => sub { + my $tagname=shift; + if ($tagname eq "a" && defined $aref) { + $aref->{title}=$abody; + $aref=undef; + $abody=undef; + } + }, "tagname"); + $parser->report_tags(qw{link a}); $parser->parse($page); $parser->eof; @@ -209,6 +231,10 @@ if (! @repos) { die "no repositories found on $url\n"; } +#use Data::Dumper; +#print Dumper(\@repos); +#exit; + if (defined $destdir && @repos > 1) { # create subdirs of $destdir for the multiple repos if (! $noact) { @@ -234,6 +260,3 @@ foreach my $repo (@repos) { } } exit($errors > 0); - -#use Data::Dumper; -#print Dumper(\@repos); -- 2.39.5