Last active
August 29, 2015 14:05
-
-
Save tsibley/b043e683d419e6e2455f to your computer and use it in GitHub Desktop.
podtogo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env plackup | |
use strict; | |
use warnings; | |
use utf8; | |
use Plack::Builder; | |
use Plack::App::Directory; | |
use HTML::Restrict; | |
use lib::remote | |
'MetaCPAN::Pod::XHTML' | |
=> 'https://raw.githubusercontent.com/CPAN-API/cpan-api/master/lib/MetaCPAN/Pod/XHTML.pm'; | |
# From MetaCPAN::Server::View::Pod | |
sub render_pod { | |
my $pod = shift; | |
my $parser = MetaCPAN::Pod::XHTML->new(); | |
$parser->index(1); | |
$parser->html_header(''); | |
$parser->html_footer(''); | |
$parser->perldoc_url_prefix(''); | |
$parser->no_errata_section(0); | |
my $html = ""; | |
$parser->output_string( \$html ); | |
$parser->parse_string_document($pod); | |
return $html; | |
} | |
# From MetaCPAN::Web::Controller::Pod->view | |
my $filter = HTML::Restrict->new; | |
$filter->set_rules( | |
{ | |
a => [qw( href target )], | |
b => [], | |
br => [], | |
caption => [], | |
center => [], | |
code => [], | |
dd => ['id'], | |
div => [qw(id style)], | |
dl => ['id'], | |
dt => ['id'], | |
em => [], | |
h1 => ['id'], | |
h2 => ['id'], | |
h3 => ['id'], | |
h4 => ['id'], | |
h5 => ['id'], | |
h6 => ['id'], | |
i => [], | |
img => [qw( alt border height width src style title / )], | |
li => ['id'], | |
ol => [], | |
p => [qw(class style)], | |
pre => [qw(id class style)], | |
span => [qw(style)], | |
strong => [], | |
sub => [], | |
sup => [], | |
table => [qw( style class border cellspacing cellpadding align )], | |
tbody => [], | |
td => [qw(style class)], | |
tr => [qw(style class)], | |
u => [], | |
ul => ['id'], | |
} | |
); | |
builder { | |
enable_if { $_[0]->{PATH_INFO} =~ /\.(pm|pl|pod)$/i } shift @$_, @$_ for | |
[ SimpleContentFilter => filter => sub { $_ = $filter->process( render_pod($_) ) } ], | |
[ Header => set => [ 'Content-Type' => 'text/html' ] ]; | |
Plack::App::Directory->new({ root => "./lib" })->to_app; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment