Skip Menu |

This queue is for tickets about the HTML-FormatText-WithLinks CPAN distribution.

Report information
The Basics
Id: 14288
Status: resolved
Priority: 0/
Queue: HTML-FormatText-WithLinks

People
Owner: struan [...] cpan.org
Requestors: at [...] altlinux.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.03
Fixed in: (no value)



Subject: anchors are are treated as links
Hello, <a> tag may or may not have "href" attribute; it may have "name" attribute instead to mark some point in the document. In the latter case, such tags should not be treated as "links" and should not be enumerated and listed in footnotes. The following patch solves the problem for me: --- lib/HTML/FormatText/WithLinks.pm- 2005-05-19 19:11:37 +0000 +++ lib/HTML/FormatText/WithLinks.pm 2005-08-23 04:54:54 +0000 @@ -58,7 +58,8 @@ sub a_start { my $self = shift; my $node = shift; # local urls are no use so we have to make them absolute - my $href = $node->attr('href') || ''; + my $href = $node->attr('href'); +if (defined $href) { if ($href =~ m#^http:|^mailto:#) { push @{$self->{_links}}, $href; } else { @@ -66,6 +67,7 @@ sub a_start { push @{$self->{_links}}, $u->abs(); } $self->out( $self->text('before_link') ); +} $self->SUPER::a_start(); } @@ -74,6 +76,8 @@ sub a_end { my $self = shift; my $node = shift; + my $href = $node->attr('href'); +if (defined $href) { my $text = $self->text('after_link'); # If we're just dealing with a fragment of HTML, with a link at the # end, we get a space before the first footnote link if we do @@ -81,6 +85,7 @@ sub a_end { if ($text ne '') { $self->out( $text ); } +} $self->SUPER::a_end(); } End of patch Thanks. -- Alexey Tourbin ALT Linux Team
As of version 0.05 and 0.06, after_link is still rendered for anchors.
On Sat Aug 26 23:25:45 2006, ATOURBIN wrote: Show quoted text
> As of version 0.05 and 0.06, after_link is still rendered for anchors.
Because the closing <a> tags are not checked for having href= attribute, there's another bug: $self->{_links} is autovivified and extra newlines are added in html_end. I.e. 75 sub a_end { 76 77 my $self = shift; 78 my $node = shift; 79 my $text = $self->text('after_link'); $self->text is always called, and 141 sub text { 142 143 my ($self, $type, $num, $href) = @_; 144 $href = $self->{_links}->[$#{$self->{_links}}] 145 unless (defined $num and defined $href); $self->text autovivifies $self->links, and 115 sub html_end { 116 117 my $self = shift; 118 if ( $self->{_links} and $self->{footnote} ) { the latter check is not in effect. So consider there's no real hrefs in the document (only anchors) but $self->{_links} is autovivified to [] (which is true value) and newlines are printed. Oops.
On Sat Aug 26 23:54:14 2006, ATOURBIN wrote: Show quoted text
> So consider there's no real hrefs in the document (only anchors) > but $self->{_links} is autovivified to [] (which is true value) > and newlines are printed. Oops.
So I've done some refactoring and I think I'll post my patch tomorrow.
Right, I've actually fixed this this time ;) It's in 0.07 which should be on a CPAN mirror sometime soon. struan