PPI::HTML(3pm)

πŸ“¦
version 1.08 Β· 6 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– PPI::HTML πŸ’–

okay bestie, so this is the manual page for PPI::HTML, living in the 3pm section of the manual, and it's literally the glow-up your Perl code deserves ✨


🌸 NAME 🌸

PPI::HTML β€” Generate syntax-hightlighted HTML for Perl using PPI πŸŽ€


✨ SYNOPSIS ✨

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 );

like, that's the whole vibe right there. four lines. icon. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

PPI::HTML converts Perl documents into syntax highlighted HTML pages. that's it, that's the job, and it does it flawlessly πŸ’…


πŸ’œ HISTORY πŸ’œ

PPI::HTML is the successor to the now-redundant PPI::Format::HTML. out with the old, in with the slay.

so back in the day, the thought was that one single formatting code could handle a whole bunch of different output types all at once (ANSI and HTML, for example β€” like, multitasking queen energy). but then the here-doc code came along and things got messy, and the need for independently written serializers showed up, and ngl that whole plan had to be thrown out entirely 😭. it's giving "we tried".

plus β€” and this is the real tea β€” the old module only made use of the Tokenizer, and honestly its API was pretty shit, to boot πŸ’€

πŸŽ€ API Overview πŸŽ€

the new module is so much cleaner, no cap. you just make an object with the options you want, pass PPI::Document objects to the "html" method, and you get back strings of HTML that you can do literally whatever you want with. main character API energy fr fr.


πŸ”₯ METHODS πŸ”₯

⭐ new %args

the "new" constructor takes a simple set of key/value pairs to define the formatting options for the HTML. easy.

  • page β€” if the "page" option is enabled, the generator will wrap the generated HTML fragment in a basic but complete page. like, full page mode, not just a lil fragment 🫢
  • line_numbers β€” at the present time, the only option available. if set to true, line numbers get added to the output. πŸ”’
  • colors | colours β€” for the cases where you don't wanna use an external stylesheet, you can hand over "colors" as a hash reference, where the keys are CSS classes (generally matching the token name) and the values are colours. this lets you do basic colouring without needing a whole entire stylesheet. casual, effortless, iconic. 🌈
  • css β€” the "css" option lets you provide a custom CSS::Tiny object containing any CSS you want to apply to the page (if you're using page mode).
⚠️ heads up bestie: if both the "colors" and "css" options are used, the colour CSS entries will overwrite anything contained in the CSS::Tiny object. also, the object will be cloned if it is to be modified, so you don't accidentally destroy any CSS objects you passed in. respect the clone πŸ’…

Returns a new PPI::HTML object πŸŽ‰

🧚 css

the "css" accessor returns the CSS::Tiny object that was originally provided to the constructor. it remembers. it always remembers.

πŸ‘‘ html $Document | $file | \$source

the main method for the class, fr. 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 😭


πŸ™ˆ SUPPORT πŸ™ˆ

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 🫢


πŸ’– AUTHOR πŸ’–

Adam Kennedy <adamk@cpan.org>

Funding provided by The Perl Foundation 🌸


🌟 SEE ALSO 🌟

<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.


and that's the whole page, bestie β€” this was PPI::HTML(3pm) from perl v5.36.0, dated 2022-11-20 πŸ’– go highlight something pretty βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from