digraphs: option to show xorg digraphs instead
[sheet.git] / digraphs.plp
1 <(common.inc.plp)><:
2
3 Html({
4         title => 'digraph cheat sheet',
5         version => 'v1.0',
6         description => [
7                 "Complete table of digraph characters from RFC-1345.",
8         ],
9         keywords => [qw'
10                 digraph compose character char glyph table unicode vim
11         '],
12         stylesheet => [qw'light'],
13         data => [qw( digraphs.inc.pl )],
14 });
15
16 :>
17 <h1>RFC-1345 Digraphs</h1>
18
19 <p>i^k in <a href="/vi">Vim</a>.
20 Also see <a href="/unicode">common digraphs</a>.</p>
21
22 <p class="aside">Unofficial <span class="u-prop ex">proposals</span>
23 are available as <a href="/digraphs.vim">ex commands</a>.</p>
24
25 <:
26 my $di = do 'digraphs.inc.pl'
27         or die "Error loading digraphs data: ", $@ // $!;
28
29 my @chars = (
30         [qw{! " % ' ( ) * + , - . /}],
31         ['0'..'9'], [qw{: ; < = > ?}],
32         ['A'..'M'], ['N'..'Z'],
33         ['a'..'m'], ['n'..'z'],
34 );
35 my @chars2 = (['_'], @chars);  # trailing character (extended set)
36 my @columns = !exists $get{split} ? \@chars2 :
37         ([@chars2[0, 1, 3, 4, 6]], [@chars2[2, 5, 7]]);
38
39 if (exists $get{xorg}) {
40         my $xorg = do 'data/digraphs-xorg.inc.pl'
41                 or die "Error loading Xorg data: ", $@ // $!;
42         $_ = [ord $_] for values %{$xorg};
43         $xorg->{$_}->[2] =  # class = same as rfc | any other spec | xorg only
44                 $di->{$_} ? $di->{$_}->[2] =~ /\bu-di\b/ ? 'l5' : 'l3' : 'l1'
45                 for keys %{$xorg};
46         $chars2[0] = [qw( # ^ _ ` ~ )];
47         @chars = @chars2;
48         $di = $xorg;
49 }
50
51 for my $colchars (@columns) {
52 print '<table class="glyphs dimap"><col>';
53 print qq'<colgroup span="$_">' for map {scalar @$_} @{$colchars};
54 print "</colgroup><col>\n";
55 for my $section (qw{thead tfoot}) {
56         print "<$section><tr><th>↳";
57         print '<th>', EscapeHTML($_) for map {@$_} @{$colchars};
58         print "<th>&nbsp;\n";
59 }
60 for my $c1group (@chars) {
61         print '<tbody>';
62         for my $c1 (@$c1group) {
63                 print '<tr><th>', EscapeHTML($c1);
64                 for my $c2 (map {@$_} @$colchars) {
65                         my $mnem = $c1 . $c2;
66                         if (not defined $di->{$mnem}) {
67                                 print '<td>';
68                                 next;
69                         }
70                         if (ref $di->{$mnem} ne 'ARRAY') {
71                                 printf '<td class="X Xr" title="%s">', EscapeHTML($mnem);
72                                 next;
73                         }
74                         my ($codepoint, $name, $prop, $script, $string) = @{ $di->{$mnem} };
75
76                         my $glyph = $string || chr $codepoint;
77                         utf8::upgrade($glyph);  # prevent latin1 output
78                         my $desc = $mnem . ($name && " ($name)");
79                         my @class = ('X', grep {$_} $prop, $script);
80
81                         $glyph = EscapeHTML($glyph);
82                         $glyph = "<span>$glyph</span>" if $script =~ /\bZs\b/;
83
84                         printf "\n".'<td class="%s" title="%s">%s',
85                                 join(' ', @class), EscapeHTML($desc), $glyph;
86                 }
87                 print "\n<th>", EscapeHTML($c1), "\n";
88         }
89 }
90 print "</table>\n";
91 print '<hr>' if exists $get{split};
92 }
93 :>
94 <div class="legend">
95         <table class="glyphs"><tr>
96         <td class="X Cc">control
97         <td class="X Zs"><span>space</span>
98         <td class="X Mn">combining
99         <td class="X Sk">spacing&nbsp;modifier
100         <td class="X Pf">quote
101         <td class="X Po">punctuation
102         <td class="X So">symbol
103         <td class="X Sm">math
104         <td class="X Sc">currency
105         <td class="X No">numeric
106         <td class="X Greek">greek
107         <td class="X Cyrillic">cyrillic
108         <td class="X Latin">latin
109         <td class="X Hebrew">hebrew
110         <td class="X Arabic">arabic
111         <td class="X Hangul">korean
112         <td class="X Hiragana">japanese
113         <td class="X Bopomofo">chinese
114         </table>
115
116         <table class="glyphs"><tr>
117         <td class="X">unicode
118         <td class="X Xl">latin1
119         <td class="X Xa">ascii
120         <td class="X u-prop">vim extension
121         <td class="X u-prop ex">proposal
122         <td class="X ex">not in vim
123         </table>
124 </div>
125