this is small script that i have used for basic patch files.
not tested with different styles and stuff. but works fine for basic needs.
#!/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~
<style type="text/css"><!--
.code {
background: #ededed;
border: 1px solid #878181;
color: black;
padding: 1em;
}
.red {
color: red;
}
.blue {
color: blue;
}
--></style>~;
##
# open patch file for reading.
open (FILE, "$patch_file") || die $!;
seek (FILE, 0, 0);
while (<FILE>) {
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 .= "</pre>\n" ) : ( $close_pre = 1 );
$html .= qq~
<pre class = "code">
@ < code class = "red">$1,$2< /code > < code class = "blue">$3,$4< /co
+de > @~;
$_ =~ s/^\@\@(?:.+)\@\@/\n/g;
}
##
# removed lines in blue color.
if ( $_ =~ m/^\-/ && !$blue ) {
$html .= "<span class = \"blue\">";
$blue = 1;
}
elsif ( $_ =~ m/^[^\-]/ && $blue ) {
$html .= "<\/span>";
$blue = 0;
}
##
# added lines in red color.
if ( $_ =~ m/^\+/ && !$red ) {
$html .= "<span class = \"red\">";
$red = 1;
}
elsif ( $_ =~ m/^[^\+]/ && $red ) {
$html .= "<\/span>";
$red = 0;
}
$_ =~ s/^[\+\-]$//g;
$_ =~ s/^([\+\-])/ /g;
$html .= $_ . "\n";
}
close (FILE);
$html .= "</pre>\n";
# finally print the whole generated html.
print $html;
exit;