sample: preview image of rendered font overview
[sheet.git] / sample.plp
1 <(common.inc.plp)><:
2
3 my $textinc = 'data/unicode-sampler/unicode.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.0',
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 printf '<p>HTML display of <a href="%s">plain text</a>', $textinc;
23 say ' intended for monospaced (terminal) output.</p>';
24
25 say '<pre>';
26 print $intro;
27
28 while (my $p = readline $source) {
29         EscapeHTML($p);
30         $p =~ s{ \A ((\pL+) \N*:) \n }{<h2 id="\L$2\E">$1</h2>}x;
31         $p =~ s{(?<=^  )([\p{Latin} ]+:)}{<em>$1</em>}gm;
32         print $p;
33 }
34
35 say "</pre>\n";