]> Sergey Matveev's repositories - public-inbox.git/commitdiff
hval: split out escape sequences to a separate table
authorEric Wong <e@80x24.org>
Mon, 21 Jan 2019 03:30:56 +0000 (03:30 +0000)
committerEric Wong <e@80x24.org>
Mon, 21 Jan 2019 03:30:56 +0000 (03:30 +0000)
We'll want to handle those escape sequences independently,
"highlight" already does HTML escaping.

lib/PublicInbox/Hval.pm

index 0315d759cbf6340c837a1fee5c01a8a8f71b63b6..4d70d5e5008c5185ad743687437039f0f49dcceb 100644 (file)
@@ -37,6 +37,21 @@ sub new_oneline {
        $class->new($raw);
 }
 
+# some of these overrides are standard C escapes so they're
+# easy-to-understand when rendered.
+my %escape_sequence = (
+       "\x00" => '\\0', # NUL
+       "\x07" => '\\a', # bell
+       "\x08" => '\\b', # backspace
+       "\x09" => "\t", # obvious to show as-is
+       "\x0a" => "\n", # obvious to show as-is
+       "\x0b" => '\\v', # vertical tab
+       "\x0c" => '\\f', # form feed
+       "\x0d" => '\\r', # carriage ret (not preceding \n)
+       "\x1b" => '^[', # ASCII escape (mutt seems to escape this way)
+       "\x7f" => '\\x7f', # DEL
+);
+
 my %xhtml_map = (
        '"' => '&#34;',
        '&' => '&#38;',
@@ -46,18 +61,7 @@ my %xhtml_map = (
 );
 
 $xhtml_map{chr($_)} = sprintf('\\x%02x', $_) for (0..31);
-# some of these overrides are standard C escapes so they're
-# easy-to-understand when rendered.
-$xhtml_map{"\x00"} = '\\0'; # NUL
-$xhtml_map{"\x07"} = '\\a'; # bell
-$xhtml_map{"\x08"} = '\\b'; # backspace
-$xhtml_map{"\x09"} = "\t"; # obvious to show as-is
-$xhtml_map{"\x0a"} = "\n"; # obvious to show as-is
-$xhtml_map{"\x0b"} = '\\v'; # vertical tab
-$xhtml_map{"\x0c"} = '\\f'; # form feed
-$xhtml_map{"\x0d"} = '\\r'; # carriage ret (not preceding \n)
-$xhtml_map{"\x1b"} = '^['; # ASCII escape (mutt seems to escape this way)
-$xhtml_map{"\x7f"} = '\\x7f'; # DEL
+%xhtml_map = (%xhtml_map, %escape_sequence);
 
 sub ascii_html {
        my ($s) = @_;