digraphs: prepare xorg comparison in prebuilt data
[sheet.git] / digraphs.plp
1 <(common.inc.plp)><:
2
3 my $mode = ($Request // '') eq 'xorg' || exists $get{xorg};
4 my $modename = $mode ? 'X.Org' : 'RFC-1345';
5 my $cmp = exists $get{cmp} ? ($get{cmp} // 1) : !!$Request;
6
7 Html({
8         title => 'digraph cheat sheet',
9         version => '1.3',
10         description => [
11                 "Complete table of digraph characters from $modename.",
12         ],
13         keywords => [qw'
14                 digraph mnemonic compose composition pair
15                 character char glyph table unicode vim xorg x11 x
16         '],
17         stylesheet => [qw'light'],
18         data => [qw( data/digraphs.inc.pl )],
19 });
20
21 :>
22 <h1><:= $modename :> Digraphs</h1>
23
24 <p>Character mnemonics following compose key ⎄<:
25 say join("\n",
26         $mode ? (
27                 ' in the X Window System (Shift+AltGr by default).',
28                 'Differences from <a href="/digraphs">RFC-1345</a> are indicated.',
29         ) : (':',
30                 'i^k in <a href="/vi">Vim</a>,',
31                 '^u^\ in <a href="/readline">Emacs</a>,',
32                 '^a^v in <a href="/screen">Screen</a>.',
33                 'Similar but different from <a href="/digraphs/xorg">X.Org</a>.',
34         ),
35         'Also see <a href="/unicode">common Unicode</a>.</p>',
36 );
37 say '<p class="aside">Unofficial <span class="u-l2">proposals</span>',
38         ' are available as <a href="/digraphs.vim">ex commands</a>.' if not $mode;
39 :>
40
41 <:
42 my $di = Data('digraphs');
43
44 if (exists $get{v}) {
45         # show characters for inverted mnemonics (vim alternatives)
46         $di->{key}->{ substr($_, 1, 1) . substr($_, 0, 1) } ||= [
47                 $di->{key}->{$_}->[0], '', 'l0 ex', '', $di->{key}->{$_}->[4]
48         ] for grep { ref $di->{key}->{$_} } keys %{ $di->{key} };
49 }
50
51 my @chars = (
52         [qw{! " % ' ( ) * + , - . /}],
53         ['0'..'9'], [qw{: ; < = > ?}],
54         ['A'..'M'], ['N'..'Z'],
55         ['a'..'m'], ['n'..'z'],
56 );
57 my @chars2 = (['_'], @chars);  # trailing character (extended set)
58 my @columns = !exists $get{split} ? \@chars2 :
59         ([@chars2[0, 1, 3, 4, 6]], [@chars2[2, 5, 7]]);
60
61 if ($mode) {
62         $di = Data('digraphs-xorg');
63         $chars2[0] = [qw( # ^ _ ` ~ )];
64         @chars = @chars2;
65 }
66
67 for my $colchars (@columns) {
68 print '<table class="glyphs dimap"><col>';
69 print qq'<colgroup span="$_">' for map {scalar @$_} @{$colchars};
70 say '</colgroup><col>';
71 for my $section (qw{thead tfoot}) {
72         print "<$section><tr><th>↳";
73         print '<th>', EscapeHTML($_) for map {@$_} @{$colchars};
74         say '<th>&nbsp;';
75 }
76 for my $c1group (@chars) {
77         print '<tbody>';
78         for my $c1 (@$c1group) {
79                 print '<tr><th>', EscapeHTML($c1);
80                 for my $c2 (map {@$_} @$colchars) {
81                         my $mnem = $c1 . $c2;
82                         if (not defined $di->{key}->{$mnem}) {
83                                 print '<td>';
84                                 next;
85                         }
86                         if (ref $di->{key}->{$mnem} ne 'ARRAY') {
87                                 printf '<td class="X Xr" title="%s">', EscapeHTML($mnem);
88                                 next;
89                         }
90                         my ($codepoint, $name, $support, $script, $string) =
91                                 @{ $di->{key}->{$mnem} };
92
93                         my $glyph = $string || chr $codepoint;
94                         utf8::upgrade($glyph);  # prevent latin1 output
95                         my $desc = $mnem . ($name && " ($name)");
96                         my @class = ('X', grep {$_} $script);
97                         push @class, $cmp ? $support : "u-$support" if $support;
98
99                         $glyph = EscapeHTML($glyph);
100                         $glyph = "<span>$glyph</span>" if $script =~ /\bZs\b/;
101
102                         printf "\n".'<td class="%s" title="%s">%s',
103                                 join(' ', @class), EscapeHTML($desc), $glyph;
104                 }
105                 say "\n<th>", EscapeHTML($c1);
106         }
107 }
108 say '</table>';
109 print '<hr>' if exists $get{split};
110 }
111
112 :>
113 <div class="legend"><: unless ($cmp) { :>
114         <table class="glyphs"><tr>
115         <td class="X Cc">control
116         <td class="X Zs"><span>space</span>
117         <td class="X Mn">combining
118         <td class="X Sk">spacing&nbsp;modifier
119         <td class="X Pf">quote
120         <td class="X Po">punctuation
121         <td class="X So">symbol
122         <td class="X Sm">math
123         <td class="X Sc">currency
124         <td class="X No">numeric
125         <td class="X Greek">greek
126         <td class="X Cyrillic">cyrillic
127         <td class="X Latin">latin
128         <td class="X Hebrew">hebrew
129         <td class="X Arabic">arabic
130         <td class="X Hangul">korean
131         <td class="X Hiragana">japanese
132         <td class="X Bopomofo">chinese
133         </table>
134 <: } :>
135         <table class="glyphs"><tr><:
136         printf qq(\n\t<td class="X %s">%s), (!$cmp && 'u-').$_, $di->{flag}->{$_}
137                 for sort keys %{ $di->{flag} };
138 :>
139         </table>
140 </div>
141