Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the String-Diff CPAN distribution.

Report information
The Basics
Id: 55265
Status: resolved
Priority: 0/
Queue: String-Diff

People
Owner: Nobody in particular
Requestors: TINITA [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.04
Fixed in: (no value)



Subject: Add escaping option for output in a webpage
Hi, thanks for String::Diff, a very useful and straightforward module. I have a suggestion: Usually if you want to display diffs on a webpage, you'd html-escape the content. But the escaping can't be done before the diff since one wants to compare the raw text not the html entities. But if I do it afterwards, I would also escape the delimiters. The only solution I have at the moment is using a unique delimiter for the remove_open, ... options, and after the diff and html-escaping turn them into <del> etc. back again. It would be cool if you could add an escape callback. Example: my $diff = diff($x, $y, remove_open => '<del>', ... escape => sub { encode_entities($_[0] }, # for example ); The _str subroutine would then look like this: sub _str { my($diff, %opts) = @_; my $str = ''; my $esc = $opts{escape}; for my $parts (@{ $diff }) { if ($parts->[0] eq '-') { $str .= $opts{remove_open}. ($esc ? $esc->($parts->[1]) : $parts->[1]) . $opts{remove_close}; } elsif ($parts->[0] eq '+') { $str .= $opts{append_open}. ($esc ? $esc->($parts->[1]) : $parts->[1]) . $opts{append_close}; } else { $str .= $esc ? $esc->($parts->[1]) : $parts->[1]; } } $str; } I would just inherit from the module but _str is a private subroutine. Overwriting _str myself is probably not a goof idea since its implementation could change. Do you think you could add that option? thanks, tina
thanks to your suggestion! I added to escape option on 0.06. thanks.