Skip to content

Commit

Permalink
Merge pull request #138 from gflohr/clean-discount-auto-links
Browse files Browse the repository at this point in the history
clean discount automatic links
  • Loading branch information
gflohr authored Dec 13, 2023
2 parents 1588286 + e634033 commit fd7a442
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/Qgoda/HTMLFilter/CleanUp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,43 @@ sub comment {
return '';
}

sub start {
my ($self, $chunk, %args) = @_;

if ('a' eq lc $args{tagname}
&& defined $args{attr}->{href}
&& $args{attr}->{href} =~ s/([!,.:;?])$//) {
$self->{__interpunction} = $1;
$chunk = '<' . $args{tagname};

my $attrseq = $args{attrseq};
my $attr = $args{attr};
foreach my $key (@$attrseq) {
my $value = $attr->{$key};

my %escapes = (
'"' => '&quot;',
'&' => '&amp;'
);
$value =~ s/(["&])/$escapes{$1}/g;
$chunk .= qq{ $key="$value"};
}

$chunk .= '>';
}

return $chunk;
}

sub end {
my ($self, $chunk, %args) = @_;

my $interpunction = delete $self->{__interpunction} // '';
if ('a' eq $args{tagname}) {
return $chunk . $interpunction;
} else {
return $interpunction . $chunk;
}
}

1;

0 comments on commit fd7a442

Please sign in to comment.