* [PATCH 0/4] viewvcs: wire up highlight to solver
@ 2019-01-27 11:48 Eric Wong
2019-01-27 11:48 ` [PATCH 1/4] wwwhighlight: read_in_full returns undef on errors Eric Wong
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Eric Wong @ 2019-01-27 11:48 UTC (permalink / raw)
To: meta
Since we go through the trouble of recreating blobs with solver;
show them with syntax-highlighting.
Fortunately, Debian systems have "libhighlight-perl" SWIG bindings
packaged. Going to hammer-away on it with check-www-inbox.perl
before deploying
Eric Wong (4):
wwwhighlight: read_in_full returns undef on errors
t/hl_mod: extra check to ensure we escape HTML
hlmod: disable enclosing <pre> tag
viewvcs: wire up syntax-highlighting for blobs
contrib/css/216dark.css | 20 ++++++++++++++++++++
lib/PublicInbox/HlMod.pm | 1 -
lib/PublicInbox/UserContent.pm | 20 ++++++++++++++++++++
lib/PublicInbox/ViewVCS.pm | 15 ++++++++++++++-
lib/PublicInbox/WwwHighlight.pm | 1 +
t/hl_mod.t | 3 ++-
6 files changed, 57 insertions(+), 3 deletions(-)
--
EW
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] wwwhighlight: read_in_full returns undef on errors
2019-01-27 11:48 [PATCH 0/4] viewvcs: wire up highlight to solver Eric Wong
@ 2019-01-27 11:48 ` Eric Wong
2019-01-27 11:48 ` [PATCH 2/4] t/hl_mod: extra check to ensure we escape HTML Eric Wong
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2019-01-27 11:48 UTC (permalink / raw)
To: meta
The return value of "print" is not undef for Perl IO::Handle.
---
lib/PublicInbox/WwwHighlight.pm | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/PublicInbox/WwwHighlight.pm b/lib/PublicInbox/WwwHighlight.pm
index 3d6ca03..09fc48a 100644
--- a/lib/PublicInbox/WwwHighlight.pm
+++ b/lib/PublicInbox/WwwHighlight.pm
@@ -52,6 +52,7 @@ sub read_in_full ($) {
$off += $r;
}
$env->{'psgi.errors'}->print("input read error: $!\n");
+ undef;
}
# entry point for PSGI
--
EW
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] t/hl_mod: extra check to ensure we escape HTML
2019-01-27 11:48 [PATCH 0/4] viewvcs: wire up highlight to solver Eric Wong
2019-01-27 11:48 ` [PATCH 1/4] wwwhighlight: read_in_full returns undef on errors Eric Wong
@ 2019-01-27 11:48 ` Eric Wong
2019-01-27 11:48 ` [PATCH 3/4] hlmod: disable enclosing <pre> tag Eric Wong
2019-01-27 11:48 ` [PATCH 4/4] viewvcs: wire up syntax-highlighting for blobs Eric Wong
3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2019-01-27 11:48 UTC (permalink / raw)
To: meta
Otherwise, it's open season on our users :<
---
t/hl_mod.t | 1 +
1 file changed, 1 insertion(+)
diff --git a/t/hl_mod.t b/t/hl_mod.t
index b8b8eb9..62cc624 100644
--- a/t/hl_mod.t
+++ b/t/hl_mod.t
@@ -20,6 +20,7 @@ my $orig = $str;
my $ref = $hls->do_hl(\$str, 'foo.perl');
is(ref($ref), 'SCALAR', 'got a scalar reference back');
like($$ref, qr/I can see you!/, 'we can see ourselves in output');
+ like($$ref, qr/&&/, 'escaped');
use PublicInbox::Spawn qw(which);
if (eval { require IPC::Run } && which('w3m')) {
--
EW
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] hlmod: disable enclosing <pre> tag
2019-01-27 11:48 [PATCH 0/4] viewvcs: wire up highlight to solver Eric Wong
2019-01-27 11:48 ` [PATCH 1/4] wwwhighlight: read_in_full returns undef on errors Eric Wong
2019-01-27 11:48 ` [PATCH 2/4] t/hl_mod: extra check to ensure we escape HTML Eric Wong
@ 2019-01-27 11:48 ` Eric Wong
2019-01-27 11:48 ` [PATCH 4/4] viewvcs: wire up syntax-highlighting for blobs Eric Wong
3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2019-01-27 11:48 UTC (permalink / raw)
To: meta
We already have a <pre> tag in ViewVCS, and nesting <pre>
inside the pre-existing <pre> overrides the "white-space:pre"
we use to align line numbers.
---
lib/PublicInbox/HlMod.pm | 1 -
t/hl_mod.t | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/lib/PublicInbox/HlMod.pm b/lib/PublicInbox/HlMod.pm
index 5cbfb29..237ffac 100644
--- a/lib/PublicInbox/HlMod.pm
+++ b/lib/PublicInbox/HlMod.pm
@@ -99,7 +99,6 @@ sub do_hl {
my $gen = $self->{$langpath} ||= do {
my $g = highlight::CodeGenerator::getInstance($highlight::HTML);
$g->setFragmentCode(1); # generate html fragment
- $g->setHTMLEnclosePreTag(1); # include <pre>
# whatever theme works
my $themepath = $dir->getThemePath('print.theme');
diff --git a/t/hl_mod.t b/t/hl_mod.t
index 62cc624..80f8890 100644
--- a/t/hl_mod.t
+++ b/t/hl_mod.t
@@ -27,7 +27,7 @@ my $orig = $str;
require File::Temp;
my $cmd = [ qw(w3m -T text/html -dump -config /dev/null) ];
my ($out, $err) = ('', '');
- IPC::Run::run($cmd, $ref, \$out, \$err);
+ IPC::Run::run($cmd, \('<pre>'.$$ref.'</pre>'), \$out, \$err);
# expand tabs and normalize whitespace,
# w3m doesn't preserve tabs
$orig =~ s/\t/ /gs;
--
EW
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] viewvcs: wire up syntax-highlighting for blobs
2019-01-27 11:48 [PATCH 0/4] viewvcs: wire up highlight to solver Eric Wong
` (2 preceding siblings ...)
2019-01-27 11:48 ` [PATCH 3/4] hlmod: disable enclosing <pre> tag Eric Wong
@ 2019-01-27 11:48 ` Eric Wong
3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2019-01-27 11:48 UTC (permalink / raw)
To: meta
And update 216dark.css to match a color scheme I'm used to;
which is fairly minimal and doesn't use all the classes
"highlight" provides.
---
contrib/css/216dark.css | 20 ++++++++++++++++++++
lib/PublicInbox/UserContent.pm | 20 ++++++++++++++++++++
lib/PublicInbox/ViewVCS.pm | 15 ++++++++++++++-
3 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/contrib/css/216dark.css b/contrib/css/216dark.css
index 2fd85d0..35ef7aa 100644
--- a/contrib/css/216dark.css
+++ b/contrib/css/216dark.css
@@ -24,3 +24,23 @@ a:visited { color:#96f }
*.del { color:#f0f }
*.head { color:#fff }
*.hunk { color:#c93 }
+
+/*
+ * highlight 3.x colors (tested 3.18)
+ * this doesn't use most of the colors available (I find too many
+ * colors overwhelming). So the #ccc default is commented out.
+ */
+.hl.num { color:#f30 }
+.hl.esc { color:#f0f }
+.hl.str { color:#f30 }
+.hl.pps { color:#f30 }
+/* .hl.slc { color:#ccc } */
+.hl.com { color:#09f }
+.hl.ppc { color:#f0f }
+/* .hl.opt { color:#ccc } */
+/* .hl.ipl { color:#ccc } */
+/* .hl.lin { color:#ccc } */
+.hl.kwa { color:#ff0 }
+.hl.kwb { color:#0ff }
+.hl.kwc { color:#ff0 }
+/* .hl.kwd { color:#ccc } */
diff --git a/lib/PublicInbox/UserContent.pm b/lib/PublicInbox/UserContent.pm
index b34ebf9..514cd95 100644
--- a/lib/PublicInbox/UserContent.pm
+++ b/lib/PublicInbox/UserContent.pm
@@ -36,6 +36,26 @@ sub CSS () {
*.del { color:#f0f }
*.head { color:#fff }
*.hunk { color:#c93 }
+
+ /*
+ * highlight 3.x colors (tested 3.18)
+ * this doesn't use most of the colors available (I find too many
+ * colors overwhelming). So the #ccc default is commented out.
+ */
+ .hl.num { color:#f30 }
+ .hl.esc { color:#f0f }
+ .hl.str { color:#f30 }
+ .hl.pps { color:#f30 }
+ /* .hl.slc { color:#ccc } */
+ .hl.com { color:#09f }
+ .hl.ppc { color:#f0f }
+ /* .hl.opt { color:#ccc } */
+ /* .hl.ipl { color:#ccc } */
+ /* .hl.lin { color:#ccc } */
+ .hl.kwa { color:#ff0 }
+ .hl.kwb { color:#0ff }
+ .hl.kwc { color:#ff0 }
+ /* .hl.kwd { color:#ccc } */
_
}
# end of auto-updated sub
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index 5de37ee..a8aa0b6 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -21,6 +21,11 @@ use PublicInbox::SolverGit;
use PublicInbox::WwwStream;
use PublicInbox::Linkify;
use PublicInbox::Hval qw(ascii_html to_filename);
+my $hl = eval {
+ require PublicInbox::HlMod;
+ PublicInbox::HlMod->new;
+};
+
my %QP_MAP = ( A => 'oid_a', B => 'oid_b', a => 'path_a', b => 'path_b' );
my $max_size = 1024 * 1024; # TODO: configurable
my $enc_utf8 = find_encoding('UTF-8');
@@ -88,6 +93,14 @@ sub solve_result {
my $nl = ($$blob =~ tr/\n/\n/);
my $pad = length($nl);
+ $l->linkify_1($$blob);
+ my $ok = $hl->do_hl($blob, $path) if $hl;
+ if ($ok) {
+ $blob = $ok;
+ } else {
+ $$blob = ascii_html($$blob);
+ }
+
# using some of the same CSS class names and ids as cgit
$log = "<pre>$oid $type $size bytes $raw_link</pre>" .
"<hr /><table\nclass=blob>".
@@ -96,7 +109,7 @@ sub solve_result {
} (1..$nl)) . '</pre></td>' .
'<td><pre> </pre></td>'. # pad for non-CSS users
"<td\nclass=lines><pre\nstyle='white-space:pre'><code>" .
- ascii_html($$blob) .
+ $l->linkify_2($$blob) .
'</code></pre></td></tr></table>' . $log;
html_page($ctx, 200, \$log);
--
EW
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-01-27 11:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-27 11:48 [PATCH 0/4] viewvcs: wire up highlight to solver Eric Wong
2019-01-27 11:48 ` [PATCH 1/4] wwwhighlight: read_in_full returns undef on errors Eric Wong
2019-01-27 11:48 ` [PATCH 2/4] t/hl_mod: extra check to ensure we escape HTML Eric Wong
2019-01-27 11:48 ` [PATCH 3/4] hlmod: disable enclosing <pre> tag Eric Wong
2019-01-27 11:48 ` [PATCH 4/4] viewvcs: wire up syntax-highlighting for blobs Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).