From 6c08f60465c441baff92074c3122fcb62457658c Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 23 Dec 2010 22:37:19 +0100 Subject: [PATCH] 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). --- Shiar_Sheet/FormatChar.pm | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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; } -- 2.30.0