X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FWwwHighlight.pm;h=75338806a449f3270232c179ecdf3218c5b3f4b0;hb=refs%2Fheads%2Fmaster;hp=3d6ca03bdf5c3bc6e82ea134708779e2fe0fc6b8;hpb=0a04fa7bd38c8f491b429dc7d8578735ca7ca3f4;p=public-inbox.git
diff --git a/lib/PublicInbox/WwwHighlight.pm b/lib/PublicInbox/WwwHighlight.pm
index 3d6ca03b..75338806 100644
--- a/lib/PublicInbox/WwwHighlight.pm
+++ b/lib/PublicInbox/WwwHighlight.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2019 all contributors
+# Copyright (C) 2019-2021 all contributors
# License: AGPL-3.0+
# Standalone PSGI app to provide syntax highlighting as-a-service
@@ -20,21 +20,16 @@
package PublicInbox::WwwHighlight;
use strict;
-use warnings;
-use HTTP::Status qw(status_message);
+use v5.10.1;
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)
@@ -51,7 +46,8 @@ sub read_in_full ($) {
return \$buf if $r == 0;
$off += $r;
}
- $env->{'psgi.errors'}->print("input read error: $!\n");
+ warn "input read error: $!";
+ undef;
}
# entry point for PSGI
@@ -62,10 +58,17 @@ sub call {
return r(405) if $req_method ne 'PUT';
my $bref = read_in_full($env) or return r(500);
- $bref = $self->do_hl($bref, $env->{PATH_INFO});
+ my $l = PublicInbox::Linkify->new;
+ $l->linkify_1($$bref);
+ 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' ];
- push @$h, 'Content-Length', bytes::length($$bref);
+ push @$h, 'Content-Length', length($$bref);
[ 200, $h, [ $$bref ] ]
}