unicode: customisable table configuration
[sheet.git] / Shiar_Sheet / FormatChar.pm
index 62f6791ba9f1e1d72332c87b30cc56b498d7dfe0..4668c5542dc1f52feacdfd972dd9f50755179064 100644 (file)
@@ -6,7 +6,7 @@ use warnings;
 use Data::Dump 'pp';
 use PLP::Functions 'EscapeHTML';
 
-our $VERSION = '1.04';
+our $VERSION = '1.05';
 
 our $diinfo = do 'digraphs.inc.pl';
 our %di = map { $diinfo->{$_}->[0] => $_ } grep { ref $diinfo->{$_} }
@@ -81,6 +81,7 @@ sub cell {
                        push @class, 'ex'; # discouraged
                }
 
+               $input =~ s/^\\//;  # escaped char
                ($cell, $title, my $class, $mnem) = $self->glyphs_html($input);
 
                if ($self->{style} = 'di') {
@@ -108,38 +109,40 @@ sub cell {
        }
 
        my $anno = '';
-       for (@{ $self->{anno} }) {
-               if (/html$/) {
-                       require HTML::Entities;
-                       if (my $entity = $HTML::Entities::char2entity{$cell}) {
-                               $entity = substr($entity, 1, -1) unless /^&/;
-                               $anno = sprintf(' <small class="digraph">%s</small>', EscapeHTML($entity));
-                               last;
+       if ($cell ne '') {
+               for (@{ $self->{anno} }) {
+                       if (/html$/) {
+                               require HTML::Entities;
+                               if (my $entity = $HTML::Entities::char2entity{$cell}) {
+                                       $entity = substr($entity, 1, -1) unless /^&/;
+                                       $anno = sprintf(' <small class="digraph">%s</small>', EscapeHTML($entity));
+                                       last;
+                               }
                        }
-               }
-               elsif ($_ eq 'xml') {
-                       $anno = sprintf(' <small class="digraph">%s</small>',
-                               sprintf '#%d', ord($cell)
-                       );
-                       last;
-               }
-               elsif ($_ eq '&xml') {
-                       $anno = sprintf(' <small class="digraph">%s</small>',
-                               sprintf '&amp;#%d;', ord($cell)
-                       );
-                       last;
-               }
-               elsif ($_ eq 'di') {
-                       if (defined $mnem and length $mnem) {
-                               $anno = sprintf(' <small class="digraph">%s</small>', EscapeHTML($mnem));
+                       elsif ($_ eq 'xml') {
+                               $anno = sprintf(' <small class="digraph">%s</small>',
+                                       sprintf '#%d', ord($cell)
+                               );
                                last;
                        }
-               }
-               else {
-                       if ($_ eq 'hex' or $cell =~ /^[^a-zA-Z]$/) {
-                               $anno = sprintf(' <small class="%s">%04X</small>', 'value', ord $cell);
+                       elsif ($_ eq '&xml') {
+                               $anno = sprintf(' <small class="digraph">%s</small>',
+                                       sprintf '&amp;#%d;', ord($cell)
+                               );
                                last;
                        }
+                       elsif ($_ eq 'di') {
+                               if (defined $mnem and length $mnem) {
+                                       $anno = sprintf(' <small class="digraph">%s</small>', EscapeHTML($mnem));
+                                       last;
+                               }
+                       }
+                       else {
+                               if ($_ eq 'hex' or $cell =~ /^[^a-zA-Z]$/) {
+                                       $anno = sprintf(' <small class="%s">%04X</small>', 'value', ord $cell);
+                                       last;
+                               }
+                       }
                }
        }
 
@@ -202,11 +205,13 @@ sub table {
 sub print {
        my $self = shift;
        while (@_) {
-               printf '<div class="section"><h2>%s</h2>'."\n\n", shift;
+               print '<div class="section">';
+               printf '<h2>%s</h2>', shift unless ref $_[0];
+               print "\n\n";
                while (ref $_[0] and $_ = shift) {
                        print $self->table($_);
                }
-               print '</div>';
+               print "\n</div>";
        }
 }