user/dev discussion of public-inbox itself
 help / color / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 6/6] wwwtext: inline sample CSS and use highlight
Date: Tue,  5 Feb 2019 11:10:53 +0000
Message-ID: <20190205111053.7155-7-e@80x24.org> (raw)
In-Reply-To: <20190205111053.7155-1-e@80x24.org>

For user documentation regarding CSS; showing users the sample
CSS with comments is probably more helpful than having
standalone documentation on CSS classes.
---
 contrib/css/216dark.css        | 30 +++++++++++++++++-------------
 lib/PublicInbox/UserContent.pm | 16 +++++++++-------
 lib/PublicInbox/WwwText.pm     | 35 +++++++++++++++++------------------
 3 files changed, 43 insertions(+), 38 deletions(-)

diff --git a/contrib/css/216dark.css b/contrib/css/216dark.css
index 882fbc4..b18b057 100644
--- a/contrib/css/216dark.css
+++ b/contrib/css/216dark.css
@@ -13,22 +13,22 @@
 a { color:#69f; text-decoration:none }
 a:visited { color:#96f }
 
-/* quoted text gets a different color */
+/* quoted text in emails gets a different color */
 *.q { color:#09f }
 
 /*
- * these may be used with cgit, too
+ * these may be used with cgit <https://git.zx2c4.com/cgit/>, too.
  * (cgit uses <div>, public-inbox uses <span>)
  */
-*.add { color:#0ff }
-*.del { color:#f0f }
-*.head { color:#fff }
-*.hunk { color:#c93 }
+*.add { color:#0ff } /* diff post-image lines */
+*.del { color:#f0f } /* diff pre-image lines */
+*.head { color:#fff } /* diff header (metainformation) */
+*.hunk { color:#c93 } /* diff hunk-header */
 
 /*
- * 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.
+ * highlight 3.x colors (tested 3.18) for displaying blobs.
+ * This doesn't use most of the colors available, as I find too
+ * many colors overwhelming, so the default is commented out.
  */
 .hl.num { color:#f30 } /* number */
 .hl.esc { color:#f0f } /* escape character */
@@ -36,11 +36,15 @@ a:visited { color:#96f }
 .hl.ppc { color:#f0f } /* preprocessor */
 .hl.pps { color:#f30 } /* preprocessor string */
 .hl.slc { color:#09f } /* single-line comment */
-.hl.com { color:#09f }
-/* .hl.opt { color:#ccc } */
-/* .hl.ipl { color:#ccc } */
-/* .hl.lin { color:#ccc } */
+.hl.com { color:#09f } /* multi-line comment */
+/* .hl.opt { color:#ccc } */ /* operator */
+/* .hl.ipl { color:#ccc } */ /* interpolation */
+
+/* keyword groups kw[a-z] */
 .hl.kwa { color:#ff0 }
 .hl.kwb { color:#0f0 }
 .hl.kwc { color:#ff0 }
 /* .hl.kwd { color:#ccc } */
+
+/* line-number (unused by public-inbox) */
+/* .hl.lin { color:#ccc } */
diff --git a/lib/PublicInbox/UserContent.pm b/lib/PublicInbox/UserContent.pm
index df0429c..468e6cf 100644
--- a/lib/PublicInbox/UserContent.pm
+++ b/lib/PublicInbox/UserContent.pm
@@ -38,9 +38,9 @@ sub CSS () {
 	*.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.
+	 * highlight 3.x colors (tested 3.18) for displaying blobs.
+	 * 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 } /* number */
 	.hl.esc { color:#f0f } /* escape character */
@@ -48,10 +48,12 @@ sub CSS () {
 	.hl.ppc { color:#f0f } /* preprocessor */
 	.hl.pps { color:#f30 } /* preprocessor string */
 	.hl.slc { color:#09f } /* single-line comment */
-	.hl.com { color:#09f }
-	/* .hl.opt { color:#ccc } */
-	/* .hl.ipl { color:#ccc } */
-	/* .hl.lin { color:#ccc } */
+	.hl.com { color:#09f } /* multi-line comment */
+	/* .hl.opt { color:#ccc } */ /* operator */
+	/* .hl.ipl { color:#ccc } */ /* interpolation */
+	/* .hl.lin { color:#ccc } */ /* line-number (unused by public-inbox) */
+
+	/* keyword groups kw[a-z] */
 	.hl.kwa { color:#ff0 }
 	.hl.kwb { color:#0f0 }
 	.hl.kwc { color:#ff0 }
diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm
index d3413ad..adadc37 100644
--- a/lib/PublicInbox/WwwText.pm
+++ b/lib/PublicInbox/WwwText.pm
@@ -10,6 +10,10 @@ use PublicInbox::WwwStream;
 use PublicInbox::Hval qw(ascii_html);
 our $QP_URL = 'https://xapian.org/docs/queryparser.html';
 our $WIKI_URL = 'https://en.wikipedia.org/wiki';
+my $hl = eval {
+	require PublicInbox::HlMod;
+	PublicInbox::HlMod->new
+};
 
 # /$INBOX/_/text/$KEY/ # KEY may contain slashes
 # For now, "help" is the only supported $KEY
@@ -61,7 +65,13 @@ sub get_text {
 
 sub _do_linkify {
 	my $l = PublicInbox::Linkify->new;
-	$_[0] = $l->linkify_2(ascii_html($l->linkify_1($_[0])));
+	$l->linkify_1($_[0]);
+	if ($hl) {
+		$hl->do_hl_text(\($_[0]));
+	} else {
+		$_[0] = ascii_html($_[0]);
+	}
+	$_[0] = $l->linkify_2($_[0]);
 }
 
 sub _srch_prefix ($$) {
@@ -91,7 +101,8 @@ sub _srch_prefix ($$) {
 sub _colors_help ($$) {
 	my ($ctx, $txt) = @_;
 	my $ibx = $ctx->{-inbox};
-	my $base_url = $ibx->base_url($ctx->{env});
+	my $env = $ctx->{env};
+	my $base_url = $ibx->base_url($env);
 	$$txt .= "color customization for $base_url\n";
 	$$txt .= <<EOF;
 
@@ -104,23 +115,11 @@ to control the colors they see:
 
 	${base_url}userContent.css
 
-CSS classes
------------
-
-	   span.q - quoted text in email messages
-
-For diff highlighting, we try to match class names with those
-used by cgit: https://git.zx2c4.com/cgit/
-
-	 span.add - diff post-image lines
-
-	 span.del - diff pre-image lines
-
-	span.head - diff header (metainformation)
-
-	span.hunk - diff hunk-header
-
+CSS sample
+----------
+```css
 EOF
+	$$txt .= PublicInbox::UserContent::sample($ibx, $env) . "```\n";
 }
 
 sub _default_text ($$$) {
-- 
EW


      parent reply index

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-05 11:10 [PATCH 0/6] highlighting cleanups + help update Eric Wong
2019-02-05 11:10 ` [PATCH 1/6] viewvcs: cleanup utf8 handling Eric Wong
2019-02-05 11:10 ` [PATCH 2/6] hlmod: hoist out do_hl_lang sub Eric Wong
2019-02-05 11:10 ` [PATCH 3/6] hlmod: make into a singleton Eric Wong
2019-02-05 11:10 ` [PATCH 4/6] hlmod: do_hl* performs src_escape immediately Eric Wong
2019-02-05 11:10 ` [PATCH 5/6] hlmod: support "```$LANG" blocks in text Eric Wong
2019-02-05 11:10 ` 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=20190205111053.7155-7-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