Hello Holli, It's really cool! But PPI::HTML already exists. Here is a small example using it, that works a lot like your example:
#!/usr/bin/perl use strict; use warnings; use HTML::Template; use HTML::Entities; use PPI; use PPI::HTML; use Data::Dumper; use MIME::Base64; die "script needs at least one file to process!\n" unless @ARGV; my @content; my $template = HTML::Template->new(filehandle => *DATA); foreach my $source (@ARGV) { my ($type) = $source =~ /\.(.*)$/; my $part; open(FILE, '<', $source) or die "dieing while trying to open $source cause of: $!\n"; my $native = join '', (<FILE>); if ($type eq 'pl' or $type eq 'pm') { my $perldoc = PPI::Document->new( \$native ); my $highlight = PPI::HTML->new(); $part = '<pre>' . $highlight->html( $perldoc ) . '</ +pre>'; } elsif ($type eq 'png') { $part = '<div class="embimg"><img src="data:image/png;base64, +'; $part .= encode_base64($native) . '" alt=""/></div>'; } else { $part = '<pre>' . encode_entities($native) . '</pre>'; } close(FILE); push @content, { source => $source, content => $part, type => $type, }; } $template->param( content => \@content, ); print $template->output(); __DATA__ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="generator" content="perl script: project_to_html.pl" /> <title>Documentation</title> <style type="text/css" media="screen"> /* <![CDATA[ */ h1 { color: #ff9; } a { color: #99f; } pre { border-width: 1px; border-style: solid; padding: 4px; background-color: #001; color: #ddd; line-height: 0.65em; } strong { color: #f99; } .default { color: #fff; background-color: #444; font-family: Arial, Helvectia; margin: 8px; } .embimg { border-width: 1px; border-style: solid; border-color: #000; background-color: #fff; margin-top: 4px; } .comment { color: #6600dd; } .keyword { color: #ff9900; } .pragma { text-style: italic; } .substitute { color: #eeee00; } .operator { color: #6666ff; } .single { color: #0c0; } .double { color: #3c3; } .symbol { color: #d66; } .structure {color: #ccc;} .word {color: #fff;} /* ]]> */ </style> </head> <body class="default"> <TMPL_LOOP NAME="content"> <h1><TMPL_VAR NAME="source"></h1> Type of file is <strong><TMPL_VAR NAME="type"></strong><br /> <TMPL_VAR NAME="content"><br /> <hr /> </TMPL_LOOP> </body> </html>

In reply to Re: perlcode to html with syntax highlighting by neniro
in thread perlcode to html with syntax highlighting by holli

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.