-
-
Save autarch/b0537244ad553e6bb715 to your computer and use it in GitHub Desktop.
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 HTML::Restrict; | |
use Plack::Builder; | |
use Plack::App::Directory; | |
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'], | |
} | |
); | |
my $head = <<'EOF'; | |
<html> | |
<head> | |
<script src="https://metacpan.org/_asset/03d122b4177e73e6f242e26cfdb2e3e2.js" type="text/javascript"></script> | |
<link href="https://metacpan.org/_asset_less/68dbbca7ad3d7d37cebae401bd725529.css" rel="stylesheet" type="text/css"> | |
</head> | |
<body> | |
<div class="container-fluid"> | |
<div class="row"> | |
<div class="main-content col-md-12"> | |
<div class="pod content anchors"> | |
EOF | |
my $foot = <<'EOF'; | |
</div> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> | |
EOF | |
builder { | |
enable_if { $_[0]->{PATH_INFO} =~ /\.(pm|pl|pod)$/i } shift @$_, @$_ | |
for [ SimpleContentFilter => filter => | |
sub { $_ = $head . $filter->process( render_pod($_) ) . $foot } ], | |
[ 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