5 if ($source =~ s{(?<=\Q.inc.pl\E)/jsonp?$}{} and -r $source) {
6 # convert perl include to json construct
7 checkmodified($source);
9 my $data = do $source or die $@ || $! || 'read error';
11 my $converter = JSON->new;
12 $converter->utf8->indent->space_after->canonical;
14 $header{content_type} = 'application/json';
15 $header{content_type} = 'text/plain' if exists $get{debug};
16 print $_, '(' for $get{callback} // ();
17 print $converter->encode($data);
18 print ')' for $get{callback} // ();
21 $header{status} = '500 File unavailable';
22 $header{content_type} = 'text/plain';
23 print "Conversion failed: $@";
29 title => "$source source code",
31 description => !$source ? 'Index of source files for this site.' : [
32 "Source code of the $source file at this site,",
33 "with syntax highlighted and references linked."
36 sheet cheat source code perl plp html agpl
38 stylesheet => [qw'light dark mono red'],
44 print "<h1>Source files</h1>";
46 print "<p>Project code distributed under the AGPL. Please contribute back.</p>";
50 say sprintf '<li><a href="/source/%s">%1$s</a></li>', EscapeHTML($_);
55 say "<h1>Source of $source</h1>";
57 if ($source =~ m{(?:/|^)\.}) {
58 die "File request not permitted\n";
60 elsif ($source =~ s{::}{/}g or !-e $source) {
63 -e ($_ = "$INC[$_]/$source") or next;
68 -r $source or die "Requested file not found\n";
70 if (eval { require Text::VimColor and Text::VimColor->VERSION(0.12) }) {
71 delete $Text::VimColor::SYNTAX_TYPE{Underlined};
73 Statement => 'strong',
78 my $hl = Text::VimColor->new(
80 vim_options => [@Text::VimColor::VIM_OPTIONS, '+:set enc=utf-8'],
82 my $parsed = $hl->marked;
85 my ($type, $contents) = @{$_};
86 $contents = decode_utf8($contents);
87 my $tag = $type && ($TYPETAG{$type} || 'span');
89 print "<$tag$arg class=\"sy-\l$type\">" if $tag;
90 if (!$type || $type eq 'Constant'
91 and $contents =~ s{^(['"]?)(/?[a-z0-9_.]+\.(?:plp?|css|js))(?=\1$)}{}) {
92 # link other page sources, stylesheets, and javascript
93 printf '%s<a href="%s">%s</a>', $1, "/source/$2", $2;
95 if (!$type and $contents =~ s/^(\s*)([A-Z]\w+(?:::\w+)+)(?![^;\s])//) {
96 # link perl module names (Xx::Xx...)
97 printf '%s<a href="%s">%s</a>', $1, "/source/$2", $2;
99 if ($type && $type eq 'Comment'
100 and $contents =~ s{^(.*? by )(tools/\S+)}{}) {
101 # link generator scripts (by tools/...)
102 printf '%s<a href="%s">%s</a>', $1, "/source/$2", $2;
104 print Text::VimColor::_xml_escape($contents);
105 print "</$tag>" if $tag;
111 print EscapeHTML(decode_utf8(ReadFile($source)));