From: Mischa POSLAWSKY Date: Thu, 23 Dec 2010 21:37:19 +0000 (+0100) Subject: formatchar: common &; optional for html entity annotation X-Git-Tag: v1.5~95 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/6c08f60465c441baff92074c3122fcb62457658c formatchar: common &; optional for html entity annotation Strip leading ampersand and trailing semicolon to reduce useless clutter unless option is prefixed by ampersand (&html instead of html). --- diff --git a/Shiar_Sheet/FormatChar.pm b/Shiar_Sheet/FormatChar.pm index 707fdc6..62f6791 100644 --- a/Shiar_Sheet/FormatChar.pm +++ b/Shiar_Sheet/FormatChar.pm @@ -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(' %s', EscapeHTML($_)); + if (my $entity = $HTML::Entities::char2entity{$cell}) { + $entity = substr($entity, 1, -1) unless /^&/; + $anno = sprintf(' %s', EscapeHTML($entity)); last; } } elsif ($_ eq 'xml') { - require HTML::Entities; $anno = sprintf(' %s', - sprintf "&#%d;", ord($cell) + sprintf '#%d', ord($cell) + ); + last; + } + elsif ($_ eq '&xml') { + $anno = sprintf(' %s', + sprintf '&#%d;', ord($cell) ); last; }