my ($self, $char) = @_;
my $codepoint = ord $char;
my $info = $self->glyph_info($codepoint);
- my ($class, $name, $mnem, $string) = @$info;
+ my ($class, $name, $mnem, $html, $string) = @$info;
my $cell = EscapeHTML($string || $char);
my $title = sprintf 'U+%04X%s', $codepoint, $name && " ($name)";
$cell = "<span>$cell</span>" if $class =~ /\bZs\b/;
$cell = ' ' if $cell eq '';
- return ($cell, EscapeHTML($title), "X $class", $mnem);
+ return ($cell, EscapeHTML($title), "X $class", $mnem, $html);
}
sub glyphs_html {
sub cell {
my ($self, $input, $html) = @_;
- my (@class, $title, $cell, $mnem);
+ my (@class, $title, $cell, $mnem, $entity);
if ($input eq '-') {
$cell = '';
}
$input =~ s/^\\//; # escaped char
- ($cell, $title, my $class, $mnem) = $self->glyphs_html($input);
+ ($cell, $title, my $class, $mnem, $entity) = $self->glyphs_html($input);
if ($self->{style} = 'di') {
if ($class =~ /\bu-di\b/) {
if ($cell ne '') {
for (@{ $self->{anno} }) {
if (/html$/) {
- require HTML::Entities;
- if (my $entity = $HTML::Entities::char2entity{$cell}) {
- $entity = substr($entity, 1, -1) unless /^&/;
+ if (defined $entity) {
+ $entity = "&$entity;" if /^&/;
$anno = sprintf(' <small class="digraph">%s</small>', EscapeHTML($entity));
last;
}
1;
} or warn "Failed reading unicode tables: $@";
+eval {
+ require HTML::Entities;
+ while (my ($char, $entity) = each %HTML::Entities::char2entity) {
+ $entity =~ /[a-zA-Z]/ or next; # only actual aliases
+ $info{$char}->{html} = substr($entity, 1, -1);
+ }
+ 1;
+} or warn "Failed importing html entities: $@";
+
my %diinc = (
'digraphs.inc.pl' => 'u-di',
);
|| { block => '?', category => 'Xn', name => '', script => '' }
} or next;
- $info->{$_} = $info{$chr}->{$_} for qw(di class string);
+ $info->{$_} = $info{$chr}->{$_} for qw(di html class string);
# categorise by unicode types and writing script
$info->{class}->{$_}++ for $info->{category};
for my $cp (sort keys %info) {
$info{$cp}->{classstr} = join(' ', sort keys %{ $info{$cp}->{class} });
# convert info hashes into arrays of strings to output in display order
- my $row = [ map { $info{$cp}->{$_} } qw/classstr name di string/ ];
+ my $row = [ map { $info{$cp}->{$_} } qw/classstr name di html string/ ];
# strip off trailing missing values (especially string may be unknown)
defined $row->[-1] ? last : pop @$row for 1 .. @$row;
# final line (assume safe within single quotes)