latin: distinguish alternative tap code name
[sheet.git] / digraphs.plp
1 <(common.inc.plp)><:
2 use 5.010;  # state
3
4 Html({
5         title => 'digraph cheat sheet',
6         version => 'v1.1',
7         description => [
8                 "Complete table of digraph characters from RFC-1345.",
9         ],
10         keywords => [qw'
11                 digraph mnemonic compose composition pair
12                 character char glyph table unicode vim
13         '],
14         stylesheet => [qw'light'],
15         data => [qw( digraphs.inc.pl )],
16 });
17
18 :>
19 <h1>RFC-1345 Digraphs</h1>
20
21 <p>Character mnemonics
22 following composition key ⎄:
23 i^k in <a href="/vi">Vim</a>,
24 ^u^\ in <a href="/readline">Emacs</a>,
25 ^a^v in <a href="/screen">Screen</a>.
26 Also see <a href="/unicode">common Unicode</a>.</p>
27
28 <p class="aside">Unofficial <span class="u-prop ex">proposals</span>
29 are available as <a href="/digraphs.vim">ex commands</a>.</p>
30
31 <:
32 my $di = do 'digraphs.inc.pl'
33         or die "Error loading digraphs data: ", $@ // $!;
34
35 if (exists $get{v}) {
36         # show characters for inverted mnemonics (vim alternatives)
37         $di->{ substr($_, 1, 1) . substr($_, 0, 1) } ||=
38                 [ $di->{$_}->[0], '', 'l0 ex', '', $di->{$_}->[4] ]
39                 for grep { ref $di->{$_} } keys %{$di};
40 }
41
42 my @chars = (
43         [qw{! " % ' ( ) * + , - . /}],
44         ['0'..'9'], [qw{: ; < = > ?}],
45         ['A'..'M'], ['N'..'Z'],
46         ['a'..'m'], ['n'..'z'],
47 );
48 my @chars2 = (['_'], @chars);  # trailing character (extended set)
49 my @columns = !exists $get{split} ? \@chars2 :
50         ([@chars2[0, 1, 3, 4, 6]], [@chars2[2, 5, 7]]);
51
52 if (exists $get{xorg}) {
53         my $xorg = do 'data/digraphs-xorg.inc.pl'
54                 or die "Error loading Xorg data: ", $@ // $!;
55         $_ = [ord $_] for values %{$xorg};
56         $xorg->{$_}->[2] = # class = compatibility
57                 $di->{$_} ? $di->{$_}->[0] != $xorg->{$_}->[0] ? 'l1' :  # conflict
58                 $di->{$_}->[2] =~ /\bu-di\b/ ? 'l5' : 'l3' : 'l2'  # rfc|any|none
59                 for keys %{$xorg};
60
61         for my $cp (map {$_->[0]} values %{$xorg}) {
62                 next if (state $seen = {})->{$cp}++;  # List::MoreUtils::uniq
63
64                 # find multiple equivalent mnemonics
65                 my @equiv = grep {$cp eq $_->[0]}
66                         map {$xorg->{$_}} sort keys %{$xorg}; # values ordered by mnem.
67
68                 # search for the most compatible match
69                 my ($compat) = sort {
70                         $equiv[$b]->[2] cmp $equiv[$a]->[2]  # highest level
71                         || $b <=> $a  # fallback to last mnemonic
72                 } 0 .. $#equiv;
73
74                 # reclassify all but one as level 0 (omitted)
75                 splice @equiv, $compat // -1, 1, ();
76                 $_->[2] = 'l0 ex' for @equiv;
77         }
78
79         $chars2[0] = [qw( # ^ _ ` ~ )];
80         @chars = @chars2;
81         $di = $xorg;
82 }
83
84 for my $colchars (@columns) {
85 print '<table class="glyphs dimap"><col>';
86 print qq'<colgroup span="$_">' for map {scalar @$_} @{$colchars};
87 print "</colgroup><col>\n";
88 for my $section (qw{thead tfoot}) {
89         print "<$section><tr><th>↳";
90         print '<th>', EscapeHTML($_) for map {@$_} @{$colchars};
91         print "<th>&nbsp;\n";
92 }
93 for my $c1group (@chars) {
94         print '<tbody>';
95         for my $c1 (@$c1group) {
96                 print '<tr><th>', EscapeHTML($c1);
97                 for my $c2 (map {@$_} @$colchars) {
98                         my $mnem = $c1 . $c2;
99                         if (not defined $di->{$mnem}) {
100                                 print '<td>';
101                                 next;
102                         }
103                         if (ref $di->{$mnem} ne 'ARRAY') {
104                                 printf '<td class="X Xr" title="%s">', EscapeHTML($mnem);
105                                 next;
106                         }
107                         my ($codepoint, $name, $prop, $script, $string) = @{ $di->{$mnem} };
108
109                         my $glyph = $string || chr $codepoint;
110                         utf8::upgrade($glyph);  # prevent latin1 output
111                         my $desc = $mnem . ($name && " ($name)");
112                         my @class = ('X', grep {$_} $prop, $script);
113
114                         $glyph = EscapeHTML($glyph);
115                         $glyph = "<span>$glyph</span>" if $script =~ /\bZs\b/;
116
117                         printf "\n".'<td class="%s" title="%s">%s',
118                                 join(' ', @class), EscapeHTML($desc), $glyph;
119                 }
120                 print "\n<th>", EscapeHTML($c1), "\n";
121         }
122 }
123 print "</table>\n";
124 print '<hr>' if exists $get{split};
125 }
126
127 if (exists $get{xorg}) {
128 :>
129 <div class="legend">
130         <table class="glyphs"><tr>
131         <td class="X l5">matching RFC-1345
132         <td class="X l3">matching proposal
133         <td class="X l2">unique to Xorg
134         <td class="X l1">conflict
135         <td class="X l0 ex">duplicate
136         </table>
137 </div>
138 <: } else { :>
139 <div class="legend">
140         <table class="glyphs"><tr>
141         <td class="X Cc">control
142         <td class="X Zs"><span>space</span>
143         <td class="X Mn">combining
144         <td class="X Sk">spacing&nbsp;modifier
145         <td class="X Pf">quote
146         <td class="X Po">punctuation
147         <td class="X So">symbol
148         <td class="X Sm">math
149         <td class="X Sc">currency
150         <td class="X No">numeric
151         <td class="X Greek">greek
152         <td class="X Cyrillic">cyrillic
153         <td class="X Latin">latin
154         <td class="X Hebrew">hebrew
155         <td class="X Arabic">arabic
156         <td class="X Hangul">korean
157         <td class="X Hiragana">japanese
158         <td class="X Bopomofo">chinese
159         </table>
160
161         <table class="glyphs"><tr>
162         <td class="X">unicode
163         <td class="X Xl">latin1
164         <td class="X Xa">ascii
165         <td class="X u-prop">vim extension
166         <td class="X u-prop ex">proposal
167         <td class="X ex">not in vim
168         </table>
169 </div>
170
171 <: }