From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id CC90E2143C for ; Mon, 21 Jan 2019 20:53:01 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 36/37] hval: split out escape sequences to a separate table Date: Mon, 21 Jan 2019 20:52:52 +0000 Message-Id: <20190121205253.10455-37-e@80x24.org> In-Reply-To: <20190121205253.10455-1-e@80x24.org> References: <20190121205253.10455-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We'll want to handle those escape sequences independently, "highlight" already does HTML escaping. --- lib/PublicInbox/Hval.pm | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm index 0315d75..4d70d5e 100644 --- a/lib/PublicInbox/Hval.pm +++ b/lib/PublicInbox/Hval.pm @@ -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 = ( '"' => '"', '&' => '&', @@ -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) = @_; -- EW