1PPI::HTML(3) User Contributed Perl Documentation PPI::HTML(3)
2
3
4
6 PPI::HTML - Generate syntax-hightlighted HTML for Perl using PPI
7
9 use PPI;
10 use PPI::HTML;
11
12 # Load your Perl file
13 my $Document = PPI::Document->load( 'script.pl' );
14
15 # Create a reusable syntax highlighter
16 my $Highlight = PPI::HTML->new( line_numbers => 1 );
17
18 # Spit out the HTML
19 print $Highlight->html( $Document );
20
22 PPI::HTML converts Perl documents into syntax highlighted HTML pages.
23
25 PPI::HTML is the successor to the now-redundant PPI::Format::HTML.
26
27 While early on it was thought that the same formatting code might be
28 able to be used for a variety of different types of things (ANSI and
29 HTML for example) later developments with the here-doc code and the
30 need for independantly written serializers meant that this idea had to
31 be discarded.
32
33 In addition, the old module only made use of the Tokenizer, and had a
34 pretty shit API to boot.
35
36 API Overview
37
38 The new module is much cleaner. Simply create an object with the
39 options you want, pass PPI::Document objects to the "html" method, and
40 you get strings of HTML that you can do whatever you want with.
41
43 new %args
44
45 The "new" constructor takes a simple set of key/value pairs to define
46 the formatting options for the HTML.
47
48 page
49 Is the "page" option is enabled, the generator will wrap the gener‐
50 ated HTML fragment in a basic but complete page.
51
52 line_numbers
53 At the present time, the only option available. If set to true,
54 line numbers are added to the output.
55
56 colors ⎪ colours
57 For cases where you don't want to use an external stylesheet, you
58 can provide "colors" as a hash reference where the keys are CSS
59 classes (generally matching the token name) and the values are
60 colours.
61
62 This allows basic colouring without the need for a whole
63 stylesheet.
64
65 css The "css" option lets you provide a custom CSS::Tiny object con‐
66 taining any CSS you want to apply to the page (if you are using
67 page mode).
68
69 If both the "colors" and "css" options are used, the colour CSS
70 entries will overwrite anything contained in the CSS::Tiny object.
71 The object will also be cloned if it to be modified, to prevent
72 destroying any CSS objects passed in.
73
74 Returns a new PPI::HTML object
75
76 css
77
78 The "css" accessor returns the CSS::Tiny object originally provided to
79 the constructor.
80
81 html $Document ⎪ $file ⎪ \$source
82
83 The main method for the class, the "html" method takes a single
84 PPI::Document object, or anything that can be turned into a PPI::Docu‐
85 ment via its "new" method, and returns a string of HTML formatted based
86 on the arguments given to the "PPI::HTML" constructor.
87
88 Returns a string, or "undef" on error.
89
91 Bugs should always be submitted via the CPAN bug tracker
92
93 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PPI-HTML>
94
95 For other issues, contact the maintainer
96
98 Adam Kennedy <cpan@ali.as>
99
100 Funding provided by The Perl Foundation
101
103 <http://ali.as/>, PPI
104
106 Copyright (c) 2005, 2006 Adam Kennedy. All rights reserved.
107
108 This program is free software; you can redistribute it and/or modify it
109 under the same terms as Perl itself.
110
111 The full text of the license can be found in the LICENSE file included
112 with this module.
113
114
115
116perl v5.8.8 2006-05-12 PPI::HTML(3)