Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-03-29 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found