4 my $mode = ($ENV{PATH_INFO} // '') eq '/xorg' || exists $get{xorg};
5 my $modename = $mode ? 'X.Org' : 'RFC-1345';
8 title => 'digraph cheat sheet',
11 "Complete table of digraph characters from $modename.",
14 digraph mnemonic compose composition pair
15 character char glyph table unicode vim xorg x11 x
17 stylesheet => [qw'light'],
18 data => [qw( digraphs.inc.pl )],
22 <h1><:= $modename :> Digraphs</h1>
24 <p>Character mnemonics following compose key ⎄<:
27 ' in the X Window System (Shift+AltGr by default).',
28 'Differences from <a href="/digraphs">RFC-1345</a> are indicated.',
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>.',
35 'Also see <a href="/unicode">common Unicode</a>.</p>',
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;
42 my $di = do 'digraphs.inc.pl'
43 or die "Error loading digraphs data: ", $@ // $!;
46 # show characters for inverted mnemonics (vim alternatives)
47 $di->{ substr($_, 1, 1) . substr($_, 0, 1) } ||=
48 [ $di->{$_}->[0], '', 'l0 ex', '', $di->{$_}->[4] ]
49 for grep { ref $di->{$_} } keys %{$di};
53 [qw{! " % ' ( ) * + , - . /}],
54 ['0'..'9'], [qw{: ; < = > ?}],
55 ['A'..'M'], ['N'..'Z'],
56 ['a'..'m'], ['n'..'z'],
58 my @chars2 = (['_'], @chars); # trailing character (extended set)
59 my @columns = !exists $get{split} ? \@chars2 :
60 ([@chars2[0, 1, 3, 4, 6]], [@chars2[2, 5, 7]]);
63 my $xorg = do 'data/digraphs-xorg.inc.pl'
64 or die "Error loading Xorg data: ", $@ // $!;
65 $_ = [ord $_] for values %{$xorg};
66 $xorg->{$_}->[2] = # class = compatibility
67 $di->{$_} ? $di->{$_}->[0] != $xorg->{$_}->[0] ? 'l1' : # conflict
68 $di->{$_}->[2] =~ /\bu-di\b/ ? 'l5' : 'l3' : 'l2' # rfc|any|none
71 for my $cp (map {$_->[0]} values %{$xorg}) {
72 next if (state $seen = {})->{$cp}++; # List::MoreUtils::uniq
74 # find multiple equivalent mnemonics
75 my @equiv = grep {$cp eq $_->[0]}
76 map {$xorg->{$_}} sort keys %{$xorg}; # values ordered by mnem.
78 # search for the most compatible match
80 $equiv[$b]->[2] cmp $equiv[$a]->[2] # highest level
81 || $b <=> $a # fallback to last mnemonic
84 # reclassify all but one as level 0 (omitted)
85 splice @equiv, $compat // -1, 1, ();
86 $_->[2] = 'l0 ex' for @equiv;
89 $chars2[0] = [qw( # ^ _ ` ~ )];
94 for my $colchars (@columns) {
95 print '<table class="glyphs dimap"><col>';
96 print qq'<colgroup span="$_">' for map {scalar @$_} @{$colchars};
97 print "</colgroup><col>\n";
98 for my $section (qw{thead tfoot}) {
99 print "<$section><tr><th>↳";
100 print '<th>', EscapeHTML($_) for map {@$_} @{$colchars};
101 print "<th> \n";
103 for my $c1group (@chars) {
105 for my $c1 (@$c1group) {
106 print '<tr><th>', EscapeHTML($c1);
107 for my $c2 (map {@$_} @$colchars) {
108 my $mnem = $c1 . $c2;
109 if (not defined $di->{$mnem}) {
113 if (ref $di->{$mnem} ne 'ARRAY') {
114 printf '<td class="X Xr" title="%s">', EscapeHTML($mnem);
117 my ($codepoint, $name, $support, $script, $string) = @{ $di->{$mnem} };
119 my $glyph = $string || chr $codepoint;
120 utf8::upgrade($glyph); # prevent latin1 output
121 my $desc = $mnem . ($name && " ($name)");
122 my @class = ('X', grep {$_} $support && "u-$support", $script);
124 $glyph = EscapeHTML($glyph);
125 $glyph = "<span>$glyph</span>" if $script =~ /\bZs\b/;
127 printf "\n".'<td class="%s" title="%s">%s',
128 join(' ', @class), EscapeHTML($desc), $glyph;
130 print "\n<th>", EscapeHTML($c1), "\n";
134 print '<hr>' if exists $get{split};
140 <table class="glyphs"><tr>
141 <td class="X l5">matching RFC-1345
142 <td class="X l3">matching proposal
143 <td class="X l2">unique to Xorg
144 <td class="X l1">conflict
145 <td class="X l0 ex">duplicate
150 <table class="glyphs"><tr>
151 <td class="X Cc">control
152 <td class="X Zs"><span>space</span>
153 <td class="X Mn">combining
154 <td class="X Sk">spacing modifier
155 <td class="X Pf">quote
156 <td class="X Po">punctuation
157 <td class="X So">symbol
158 <td class="X Sm">math
159 <td class="X Sc">currency
160 <td class="X No">numeric
161 <td class="X Greek">greek
162 <td class="X Cyrillic">cyrillic
163 <td class="X Latin">latin
164 <td class="X Hebrew">hebrew
165 <td class="X Arabic">arabic
166 <td class="X Hangul">korean
167 <td class="X Hiragana">japanese
168 <td class="X Bopomofo">chinese
171 <table class="glyphs"><tr>
172 <td class="X u-l4">full support
173 <td class="X u-l3">vim extension
174 <td class="X u-l3 ex">vim v8.0
175 <td class="X u-l2">proposal
176 <td class="X u-l1">not in vim