{"id":20550178,"url":"https://github.com/dnmfarrell/ppi-prettify","last_synced_at":"2026-05-26T13:34:01.998Z","repository":{"id":19762117,"uuid":"23019780","full_name":"dnmfarrell/ppi-prettify","owner":"dnmfarrell","description":"A Perl HTML pretty printer to use with Google prettify CSS skins, no JavaScript required! ","archived":false,"fork":false,"pushed_at":"2017-06-21T16:39:22.000Z","size":120,"stargazers_count":0,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-06T05:43:40.847Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dnmfarrell.png","metadata":{"files":{"readme":"README.pod","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-16T14:38:24.000Z","updated_at":"2014-09-10T06:18:00.000Z","dependencies_parsed_at":"2022-09-08T07:50:35.345Z","dependency_job_id":null,"html_url":"https://github.com/dnmfarrell/ppi-prettify","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnmfarrell%2Fppi-prettify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnmfarrell%2Fppi-prettify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnmfarrell%2Fppi-prettify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnmfarrell%2Fppi-prettify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dnmfarrell","download_url":"https://codeload.github.com/dnmfarrell/ppi-prettify/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnmfarrell%2Fppi-prettify/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259067304,"owners_count":22800308,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T02:23:43.670Z","updated_at":"2025-12-12T02:46:20.140Z","avatar_url":"https://github.com/dnmfarrell.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"=head1 NAME\n\nPPI::Prettify - A Perl HTML pretty printer to use with Google prettify CSS\nskins, no JavaScript required!\n\n=head1 VERSION\n\nversion 0.07\n\n=head1 SYNOPSIS\n\n    use PPI::Prettify 'prettify';\n\n    my $codeSample = q! # get todays date in Perl\n                        use Time::Piece;\n                        print Time::Piece-\u003enew;\n                      !;\n\n    my $html = prettify({ code =\u003e $codeSample });\n\n    # every Perl token wrapped in a span e.g. for \"use PPI::Prettify;\":\n        \u003cspan class=\"kwd\"\u003euse\u003c/span\u003e\n        \u003cspan class=\"pln\"\u003e \u003c/span\u003e\n        \u003cspan class=\"atn\"\u003ePPI::Prettify\u003c/span\u003e\n        \u003cspan class=\"pln\"\u003e;\u003c/span\u003e\n\n    my $htmlDebug = prettify({ code =\u003e $codeSample, debug =\u003e 1 });\n    # with PPI::Token class, e.g. for \"use PPI::Prettify;\":\n        \u003cspan class=\"kwd\" title=\"PPI::Token::Function\"\u003euse\u003c/span\u003e\n        \u003cspan class=\"pln\" title=\"PPI::Token::Whitespace\"\u003e \u003c/span\u003e\n        \u003cspan class=\"atn\" title=\"PPI::Token::Word\"\u003ePPI::Prettify\u003c/span\u003e\n        \u003cspan class=\"pln\" title=\"PPI::Token::Structure\"\u003e;\u003c/span\u003e\n\n=head1 DESCRIPTION\n\nThis module takes a string Perl code sample and returns the tokens of the code\nsurrounded with \u003cspan\u003e tags. The class attributes are the same used by the\nL\u003cprettify.js|https://code.google.com/p/google-code-prettify/\u003e. Using\nL\u003cPPI::Prettify\u003e you can generate the prettified code for use in webpages\nwithout using JavaScript but you can use all L\u003cthe CSS\nskins|https://google-code-prettify.googlecode.com/svn/trunk/styles/index.html\u003e\ndeveloped for prettify.js. Also, because this module uses L\u003cPPI::Document\u003e to\ntokenize the code, it's more accurate than prettify.js.\n\nL\u003cPPI::Prettify\u003e exports prettify() and the $MARKUP_RULES hashref which is used\nto match PPI::Token classes to the class attribute given to that token's \u003cspan\u003e\ntag. You can modify $MARKUP_RULES to tweak the mapping if you require it.\n\nI wrote an article with more detail about the module for:\nL\u003cPerlTricks.com|http://perltricks.com/article/60/2014/1/13/Display-beautiful-Perl-code-in-HTML-without-JavaScript\u003e.\n\n=head1 MOTIVATION\n\nI wanted to generate marked-up Perl code without using JavaScript for\nL\u003cPerlTricks.com|http://perltricks.com\u003e. I was dissatisfied with prettify.js as\nit doesn't always tokenize Perl correctly and won't run if the user has\ndisabled JavaScript. I considered L\u003cPPI::HTML\u003e but it embeds the CSS in the\ngenerated code, and I wanted to use the same markup class attributes as\nprettify.js so I could reuse the existing CSS developed for it.\n\n=head1 BUGS AND LIMITATIONS\n\n=over 4\n\n=item *\n\nWhat constitutes a function and a keyword is somewhat arbitrary in Perl.\nL\u003cPPI::Prettify\u003e mostly uses L\u003cB::Keywords\u003e to help distinguish functions and\nkeywords. However, some words such as \"if\", \"my\" and \"BEGIN\" are given a\nspecial class of \"PPI::Token::KeywordFunction\" which can be overridden in\n$MARKUP_RULES, should you wish to display these as keywords instead of\nfunctions.\n\n=item *\n\nThis module does not yet process Perl code samples with heredocs correctly.\n\n=item *\n\nLine numbering needs to be added.\n\n=back\n\n=head1 SUBROUTINES/METHODS\n\n=head2 prettify\n\nTakes a hashref consisting of $code and an optional debug flag. Every Perl code\ntoken is given a \u003cspan\u003e tag that corresponds to the tags used by Google's\nprettify.js library. If debug =\u003e 1, then every token's span tag will be given a\ntitle attribute with the value of the originating PPI::Token class. This can\nhelp if you want to override the mappings in $MARKUP_RULES. See L\u003c/SYNOPSIS\u003e\nfor examples.\n\n=head2 getExampleHTML\n\nReturns an HTML document as a string with built-in CSS to demo the syntax\nhighlighting capabilites of PPI::Prettify. At the command line:\n\n    $ perl -MPPI::Prettify -e 'print PPI::Prettify::getExampleHTML()' \u003e example.html\n\n=head1 INTERNAL FUNCTIONS\n\n=head2 _decorate\n\nIterates through the tokens of a L\u003cPPI::Document\u003e, marking up each token with a\n\u003cspan\u003e tag.\n\n=head2 _to_html\n\nMarks up a token with a span tag with the appropriate class attribute and the\nPPI::Token class.\n\n=head2 _determine_token\n\nDetermines the PPI::Token type.\n\n=head1 REPOSITORY\n\nL\u003chttps://github.com/sillymoose/ppi-prettify\u003e\n\n=head1 SEE ALSO\n\nL\u003cPPI::HTML\u003e is another prettifier for Perl code samples that allows the\nembedding of CSS directly into the HTML generation.\n\n=head1 THANKS\n\nThanks to Adam Kennedy for developing L\u003cPPI::Document\u003e, without which this\nmodule would not be possible.\n\n=head1 AUTHOR\n\nDavid Farrell \u003csillymoos@cpan.org\u003e L\u003cPerlTricks.com|http://perltricks.com\u003e\n\n=head1 COPYRIGHT AND LICENSE\n\nThis software is copyright (c) 2014 by David Farrell.\n\nThis is free software; you can redistribute it and/or modify it under the same\nterms as the Perl 5 programming language system itself.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdnmfarrell%2Fppi-prettify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdnmfarrell%2Fppi-prettify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdnmfarrell%2Fppi-prettify/lists"}