Section: User Contributed Perl Documentation (3)
PPI::HTML - Generate syntax-hightlighted HTML for Perl using PPI
use PPI; use PPI::HTML; # Load your Perl file my $Document = PPI::Document->load( 'script.pl' ); # Create a reusable syntax highlighter my $Highlight = PPI::HTML->new( line_numbers => 1 ); # Spit out the HTML print $Highlight->html( $Document );
converts Perl documents into syntax highlighted HTML
is the successor to the now-redundant PPI::Format::HTML.
While early on it was thought that the same formatting code might be ableto be used for a variety of different types of things (ANSI and HTML forexample) later developments with the here-doc code and the need forindependantly written serializers meant that this idea had to be discarded.
In addition, the old module only made use of the Tokenizer, and had apretty shit API to boot.
The new module is much cleaner. Simply create an object with the optionsyou want, pass PPI::Document objects to the "html"
method,and you get strings of HTML
that you can do whatever you want with.
constructor takes a simple set of key/value pairs to definethe formatting options for the HTML
- Is the "page" option is enabled, the generator will wrap the generatedHTML fragment in a basic but complete page.
- At the present time, the only option available. If set to true, linenumbers are added to the output.
- colors | colours
- For cases where you don't want to use an external stylesheet, youcan provide "colors" as a hash reference where the keys are CSS classes(generally matching the token name) and the values are colours.
This allows basic colouring without the need for a whole stylesheet.
- The "css" option lets you provide a custom CSS::Tiny object containingany CSS you want to apply to the page (if you are using page mode).
If both the "colors" and "css" options are used, the colour CSS entrieswill overwrite anything contained in the CSS::Tiny object. The objectwill also be cloned if it to be modified, to prevent destroying any CSSobjects passed in.
Returns a new PPI::HTML object
accessor returns the CSS::Tiny object originally providedto the constructor.
html $Document | $file | \$source
The main method for the class, the "html"
method takes a singlePPI::Document object, or anything that can be turned into aPPI::Document via its "new"
method, and returns a string of HTML
formatted based on the arguments given to the "PPI::HTML"
Returns a string, or "undef" on error.
Bugs should always be submitted via the CPAN
For other issues, contact the maintainer
Adam Kennedy <adamkAATTcpan.org>
Funding provided by The Perl Foundation
Copyright 2005 - 2009 Adam Kennedy.
This program is free software; you can redistributeit and/or modify it under the same terms as Perl itself.
The full text of the license can be found in theLICENSE file included with this module.
- API Overview
- new %args
- html $Document | $file | \$source
- SEE ALSO
This document was created byman2html,using the manual pages.