#!/usr/bin/perl -w # very quick code.. use strict; my %html = ('&' => 'amp', '>' => 'gt', '<' => 'lt', '"' => 'quot'); my ( $i, $red, $blue, $close_pre, $html ); my $max = 120; # char width to break. tabs may break it. my $patch_file = "/path/to/file.patch"; ## # begin html code. $html = qq~ ~; ## # open patch file for reading. open (FILE, "$patch_file") || die $!; seek (FILE, 0, 0); while () { chomp $_; ++$i; next if $i < 3; # i wanted to use image but they say i can't use img tag inside pre :/ $_ =~ s/(.{$max}.)/$1\n+/g; $_ =~ s/([&><\"])/&$html{$1};/g; if ( $_ =~ m/^\@\@\s\-(\d+)\,(\d+)\s\+(\d+)\,(\d+)\s\@\@/ ) { ( $close_pre ) ? ( $html .= "\n" ) : ( $close_pre = 1 ); $html .= qq~
@ < code class = "red">$1,$2< /code > < code class = "blue">$3,$4< /code > @~;

$_ =~ s/^\@\@(?:.+)\@\@/\n/g;
}

##
# removed lines in blue color.

if ( $_ =~ m/^\-/ && !$blue ) {
 $html .= "";
 $blue = 1;
}

elsif ( $_ =~ m/^[^\-]/ && $blue ) {
 $html .= "<\/span>";
 $blue = 0;
}


##
# added lines in red color.
if ( $_ =~ m/^\+/ && !$red ) {
 $html .= "";
 $red = 1;
}

elsif ( $_ =~ m/^[^\+]/ && $red ) {
 $html .= "<\/span>";
 $red = 0;
}


$_ =~ s/^[\+\-]$//g;
$_ =~ s/^([\+\-])/ /g;
$html .= $_ . "\n";
}

close (FILE);

$html .= "
\n"; # finally print the whole generated html. print $html; exit;