PPI::HTML(3pm) | User Contributed Perl Documentation | PPI::HTML(3pm) |
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 );
PPI::HTML converts Perl documents into syntax highlighted HTML pages.
PPI::HTML is the successor to the now-redundant PPI::Format::HTML.
While early on it was thought that the same formatting code might be able to be used for a variety of different types of things (ANSI and HTML for example) later developments with the here-doc code and the need for independently written serializers meant that this idea had to be discarded.
In addition, the old module only made use of the Tokenizer, and had a pretty shit API to boot.
The new module is much cleaner. Simply create an object with the options you want, pass PPI::Document objects to the "html" method, and you get strings of HTML that you can do whatever you want with.
The "new" constructor takes a simple set of key/value pairs to define the formatting options for the HTML.
This allows basic colouring without the need for a whole stylesheet.
If both the "colors" and "css" options are used, the colour CSS entries will overwrite anything contained in the CSS::Tiny object. The object will also be cloned if it to be modified, to prevent destroying any CSS objects passed in.
Returns a new PPI::HTML object
The "css" accessor returns the CSS::Tiny object originally provided to the constructor.
The main method for the class, the "html" method takes a single PPI::Document object, or anything that can be turned into a PPI::Document via its "new" method, and returns a string of HTML formatted based on the arguments given to the "PPI::HTML" constructor.
Returns a string, or "undef" on error.
Bugs should always be submitted via the CPAN bug tracker
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PPI-HTML>
For other issues, contact the maintainer
Adam Kennedy <adamk@cpan.org>
Funding provided by The Perl Foundation
<http://ali.as/>, PPI
Copyright 2005 - 2009 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
2018-07-08 | perl v5.26.2 |