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;

In reply to diff to simple html by coldhawk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.