X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FWwwHighlight.pm;h=170bfcaa470165c93709e53f0d120b5e9f55e4bc;hb=95bdac7f09c69036efed537a4d03d5bdd2ae4eb6;hp=d8101b7555b8c832de1dddccea843f2346e3290b;hpb=39005a442b1fa72a3c4008d414823a9073e354bb;p=public-inbox.git diff --git a/lib/PublicInbox/WwwHighlight.pm b/lib/PublicInbox/WwwHighlight.pm index d8101b75..170bfcaa 100644 --- a/lib/PublicInbox/WwwHighlight.pm +++ b/lib/PublicInbox/WwwHighlight.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2019 all contributors +# Copyright (C) 2019-2020 all contributors # License: AGPL-3.0+ # Standalone PSGI app to provide syntax highlighting as-a-service @@ -22,21 +22,15 @@ package PublicInbox::WwwHighlight; use strict; use warnings; 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); +use PublicInbox::WwwStatic qw(r); # TODO: support highlight(1) for distros which don't package the # SWIG extension. Also, there may be admins who don't want to # have ugly SWIG-generated code in a long-lived Perl process. -sub r ($) { - my ($code) = @_; - my $msg = status_message($code); - my $len = length($msg); - [ $code, [qw(Content-Type text/plain Content-Length), $len], [$msg] ] -} - # another slurp API hogging up all my memory :< # This is capped by whatever the PSGI server allows, # $ENV{GIT_HTTP_MAX_REQUEST_BUFFER} for PublicInbox::HTTP (10 MB) @@ -67,7 +61,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' ];