font: html encode control characters
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 25 Jan 2024 19:26:22 +0000 (20:26 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 29 Jan 2024 17:17:48 +0000 (18:17 +0100)
Replace unintended commands (i.e. tab, newline) by rendered glyphs if
declared by a font, such as C1 characters following CP-1252 in Unifont.

font.plp

index a460144ca6046d5e9dc301fdf831900361a78ac4..a9f3491b1893dc83bd2466e1c9882322e252b6d5 100644 (file)
--- a/font.plp
+++ b/font.plp
@@ -156,12 +156,13 @@ EOT
                my ($class, $name, $mnem, $entity, $string) = @{$info};
                my $np = $class =~ /\bC\S\b/;  # noprint if control or invalid
                # display literal character, with placeholder circle if non-spacing/enclosing
-               my $html = ($class =~ /\bM[ne]\b/ && chr 9676) . EscapeHTML(chr $cp);
+               my $html = $np ? !!$cover{$cp} && sprintf("&#%d;", $cp) :
+                       ($class =~ /\bM[ne]\b/ && chr 9676) . EscapeHTML(chr $cp);
                say sprintf '<td class="%s" title="U+%04X%s">%s',
                        !$class ? ('l0', $cp, '', '') : (
                        $cover{$cp} ? $np ? 'l2' : 'l5' : $np ? 'Xi' : 'l1',
                        $cp, !!$name && ": $name",
-                       ($cover{$cp} || !$np) && $html
+                       $html
                        );
        }
        say '</table>';