Debian Codegraph @

htmldiff

raw
1 #!/usr/bin/perl
2
3 #
4 # htmldiff uses HTML::Diff to create an HTML file that shows the difference
5 # between two HTML files, given on the command line.
6 #
7 # Contributed by Maurice Aubrey <[email protected]>
8 #
9
10 use strict;
11 use HTML::Diff;
12
13 @ARGV == 2 or die "Usage: $0 <file1> <file2>\n";
14
15 my @txt;
16 foreach (@ARGV) {
17 open my $fh, $_ or die "unable to read '$_': $!";
18 local $/;
19 push @txt, scalar <$fh>;
20 }
21
22 print qq{<style type="text/css"><!-- ins{color: green} del{color:red}--></style>\n};
23 foreach (@{ html_word_diff(@txt) }) {
24 my($type, $left, $right) = @$_;
25
26 # debug
27 #$left =~ s/\n/ /g;
28 #$right =~ s/\n/ /g;
29 #print "TYPE:$type\nLEFT: $left\nRIGHT: $right\n\n";
30 #next;
31
32 if ($type eq 'u') {
33 print $left;
34 } else {
35 print "<del>$left</del>" if length $left;
36 print "<ins>$right</ins>" if length $right;
37 }
38 }