formatchar: common &; optional for html entity annotation
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 23 Dec 2010 21:37:19 +0000 (22:37 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 11 Jan 2011 22:41:38 +0000 (23:41 +0100)
Strip leading ampersand and trailing semicolon to reduce useless clutter
unless option is prefixed by ampersand (&html instead of html).

Shiar_Sheet/FormatChar.pm

index 707fdc6..62f6791 100644 (file)
@@ -109,17 +109,23 @@ sub cell {
 
        my $anno = '';
        for (@{ $self->{anno} }) {
-               if ($_ eq 'html') {
+               if (/html$/) {
                        require HTML::Entities;
-                       if (my $_ = $HTML::Entities::char2entity{$cell}) {
-                               $anno = sprintf(' <small class="digraph">%s</small>', EscapeHTML($_));
+                       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') {
-                       require HTML::Entities;
                        $anno = sprintf(' <small class="digraph">%s</small>',
-                               sprintf "&amp;#%d;", ord($cell)
+                               sprintf '#%d', ord($cell)
+                       );
+                       last;
+               }
+               elsif ($_ eq '&xml') {
+                       $anno = sprintf(' <small class="digraph">%s</small>',
+                               sprintf '&amp;#%d;', ord($cell)
                        );
                        last;
                }