]> Sergey Matveev's repositories - public-inbox.git/commitdiff
wwwhighlight: deal with no-op highlight
authorEric Wong <e@80x24.org>
Wed, 24 Apr 2019 21:56:53 +0000 (21:56 +0000)
committerEric Wong <e@80x24.org>
Wed, 24 Apr 2019 22:40:17 +0000 (22:40 +0000)
Not all inputs are highlight-able, so reuse the original
input and just linkify it if it can't be highlighted.

lib/PublicInbox/WwwHighlight.pm

index d8101b7555b8c832de1dddccea843f2346e3290b..bc349f8a7a1e633617be39ef6e8028af05a2290f 100644 (file)
@@ -25,6 +25,7 @@ use bytes (); # only for bytes::length
 use HTTP::Status qw(status_message);
 use parent qw(PublicInbox::HlMod);
 use PublicInbox::Linkify qw();
+use PublicInbox::Hval qw(ascii_html);
 
 # TODO: support highlight(1) for distros which don't package the
 # SWIG extension.  Also, there may be admins who don't want to
@@ -67,7 +68,11 @@ sub call {
        my $bref = read_in_full($env) or return r(500);
        my $l = PublicInbox::Linkify->new;
        $l->linkify_1($$bref);
-       $bref = $self->do_hl($bref, $env->{PATH_INFO});
+       if (my $res = $self->do_hl($bref, $env->{PATH_INFO})) {
+               $bref = $res;
+       } else {
+               $$bref = ascii_html($$bref);
+       }
        $l->linkify_2($$bref);
 
        my $h = [ 'Content-Type', 'text/html; charset=UTF-8' ];