Subject: | Patch to reset internal links before parsing |
Hi,
if a HTML::FormatText::WithLinks object is used to parse multiple html
chunks with links in it, the links from all chunks continuously sum up.
The obvious solution is to clear the internal links before starting in
the _parse() method.
I've attached a fix plus a corresponding test case (shouldn't conflict
wit h the previous patch i sent).
Regards,
Simon
Subject: | HTML-FormatText-WithLinks-multiparse.diff |
--- lib/HTML/FormatText/WithLinks.pm.orig Sat Jul 12 13:26:33 2008
+++ lib/HTML/FormatText/WithLinks.pm Sat Jul 12 13:28:31 2008
@@ -207,6 +207,9 @@ sub _parse {
my $self = shift;
my $tree = shift;
+ $self->{_link_track} = {};
+ $self->{_links} = [];
+
unless ( $tree ) {
$self->error( "HTML::TreeBuilder problem" . ( $! ? ": $!" : '' ) );
return undef;
--- /dev/null Sat Jul 12 13:34:41 2008
+++ t/16_parse_multiple_times.t Sat Jul 12 13:33:39 2008
@@ -0,0 +1,54 @@
+# $Id$
+
+use Test::More tests => 5;
+use HTML::FormatText::WithLinks;
+
+my $html_link = new_html_link();
+my $html = new_html();
+my $f = HTML::FormatText::WithLinks->new( leftmargin => 0 );
+
+ok($f, 'object created');
+
+my $text = $f->parse($html_link);
+
+my $correct_text = qq!This is a mail of some sort with a [1]link.
+
+
+
+1. http://example.com/
+
+
+!;
+
+ok($text, 'html formatted');
+is($text, $correct_text, 'html correctly formatted');
+
+$text = $f->parse($html);
+
+ok($text, 'html formatted');
+is($text, "\n\nThis is a mail of some sort\n\n",
+ 'html correctly formatted with no left margin');
+
+sub new_html_link {
+return <<'HTML';
+<html>
+<body>
+<p>
+This is a mail of some sort with a <a href="http://example.com/">link</a>.
+</p>
+</body>
+</html>
+HTML
+}
+
+sub new_html {
+return <<'HTML';
+<html>
+<body>
+<p>
+This is a mail of some sort
+</p>
+</body>
+</html>
+HTML
+}