File: htmldiff

package info (click to toggle)
libhtml-diff-perl 0.600-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, stretch
  • size: 104 kB
  • ctags: 15
  • sloc: perl: 520; makefile: 8
file content (38 lines) | stat: -rw-r--r-- 835 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/perl

#
# htmldiff uses HTML::Diff to create an HTML file that shows the difference
# between two HTML files, given on the command line.
#
# Contributed by Maurice Aubrey <maurice@redweek.com>
#

use strict;
use HTML::Diff;

@ARGV == 2 or die "Usage: $0 <file1> <file2>\n";

my @txt;
foreach (@ARGV) {
  open my $fh, $_ or die "unable to read '$_': $!";
  local $/;
  push @txt, scalar <$fh>;
}

print qq{<style type="text/css"><!-- ins{color: green} del{color:red}--></style>\n};
foreach (@{ html_word_diff(@txt) }) {
  my($type, $left, $right) = @$_;

  # debug
  #$left =~ s/\n/ /g;
  #$right =~ s/\n/ /g;
  #print "TYPE:$type\nLEFT: $left\nRIGHT: $right\n\n";
  #next;

  if ($type eq 'u') {
    print $left;
  } else {
    print "<del>$left</del>" if length $left;
    print "<ins>$right</ins>" if length $right;
  }
}