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