user/dev discussion of public-inbox itself
 help / color / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 4/4] viewvcs: wire up syntax-highlighting for blobs
Date: Sun, 27 Jan 2019 11:48:17 +0000
Message-ID: <20190127114817.14486-5-e@80x24.org> (raw)
In-Reply-To: <20190127114817.14486-1-e@80x24.org>

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


      parent reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Eric Wong [this message]

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190127114817.14486-5-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox