sample: serve text file as proper sample.txt page
[sheet.git] / sample.plp
1 <(common.inc.plp)><:
2
3 my $textinc = 'sample.txt';
4 my $proto = sprintf('http%s://', !!$ENV{HTTPS} && 's');
5 my $preview = "$proto$ENV{HTTP_HOST}/sample.png";
6
7 Html({
8         title => "unicode sampler",
9         version => '2.1',
10         stylesheet => [qw'light dark mono red'],
11         data => [$textinc],
12         raw => qq(<meta property="og:image" content="$preview" />),
13 });
14
15 open my $source, '<', $textinc
16         or Abort("Could not open text at $textinc", 501, $!);
17 local $/ = "\n\n";
18
19 my $top = readline $source;
20 my ($title, $hr, $intro) = split /\n(\pP)\1+\n/, $top, 2;
21 say "<h1>$title</h1>";
22 say <<".";
23 <p>HTML display of <a href="/$textinc">plain text</a>
24 intended for monospaced (terminal) output.
25 Compare an expected rendering of the <a href="/sample.png">overview</a>.
26 </p>
27 .
28
29 say '<pre>';
30 print $intro;
31
32 while (my $p = readline $source) {
33         EscapeHTML($p);
34         $p =~ s{ \A ((\pL+) \N*:) \n }{<h2 id="\L$2\E">$1</h2>}x;
35         if ($2 eq 'Unicode') {
36                 # table without proper direction control
37                 $p =~ s/^(?= )/\x{202d}/gm; # ltr override every line
38         }
39         $p =~ s{(?<=^  )([\p{Latin} ]+:)}{<em>$1</em>}gm;
40         print $p;
41 }
42
43 say "</pre>\n";