3 my $source = $ENV{PATH_INFO};
7 title => "$source source code",
9 description => !$source ? 'Index of source files for this site.' : [
10 "Source code of the $source file at this site,",
11 "with syntax highlighted and references linked."
14 sheet cheat source code perl plp html agpl
16 stylesheet => [qw'light dark mono red'],
22 print "<h1>Source files</h1>";
24 print "<p>Project code distributed under the AGPL. Please contribute back.</p>";
28 printf '<li><a href="/source/%s">%1$s</a></li>'."\n", EscapeHTML($_);
33 print "<h1>Source of $source</h1>\n";
35 if ($source =~ m{(?:/|^)\.}) {
36 die "File request not permitted\n";
38 elsif ($source =~ s{::}{/}g or !-e $source) {
41 -e ($_ = "$INC[$_]/$source") or next;
46 -r $source or die "Requested file not found\n";
48 if (eval { require Text::VimColor and Text::VimColor->VERSION(0.12) }) {
49 delete $Text::VimColor::SYNTAX_TYPE{Underlined};
51 Statement => 'strong',
56 my $hl = Text::VimColor->new(
58 vim_options => [@Text::VimColor::VIM_OPTIONS, '+:set enc=utf-8'],
60 my $parsed = $hl->marked;
63 my $tag = $_->[0] && ($TYPETAG{ $_->[0] } || 'span');
65 print "<$tag$arg class=\"sy-\l$_->[0]\">" if $tag;
66 if (!$_->[0] || $_->[0] eq 'Constant'
67 and $_->[1] =~ s{^(['"]?)(/?[a-z0-9_.]+\.(?:plp?|css|js))(?=\1$)}{}) {
68 printf '%s<a href="%s">%s</a>', $1, "/source/$2", $2;
70 if (!$_->[0] and $_->[1] =~ s/^(\s*)([A-Z]\w+(?:::\w+)+)(?![^;\s])//) {
71 printf '%s<a href="%s">%s</a>', $1, "/source/$2", $2;
73 print Text::VimColor::_xml_escape($_->[1]);
74 print "</$tag>" if $tag;
79 print "<pre>\n", EscapeHTML(ReadFile($source)), "</pre>\n";