user/dev discussion of public-inbox itself
 help / color / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: Dmitry Alexandrov <321942@gmail.com>,
	Mateusz Loskot <mateusz@loskot.net>
Subject: [PATCH 1/2] usercontent.pm: set "!important" to override BOFH prefs
Date: Sat, 23 Feb 2019 10:56:37 +0000
Message-ID: <20190223105638.15465-2-e@80x24.org> (raw)
In-Reply-To: <20190223105638.15465-1-e@80x24.org>

The sample userContent.css needs a higher priority than what
the BOFH specifies.  In other words, user preference must
ALWAYS take precedence.

Reported-by: Dmitry Alexandrov <321942@gmail.com>
cf. https://public-inbox.org/meta/87mumn4kx8.fsf@gmail.com/
---
 lib/PublicInbox/UserContent.pm | 41 +++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 16 deletions(-)

diff --git a/lib/PublicInbox/UserContent.pm b/lib/PublicInbox/UserContent.pm
index 468e6cf..5e57602 100644
--- a/lib/PublicInbox/UserContent.pm
+++ b/lib/PublicInbox/UserContent.pm
@@ -16,31 +16,31 @@ sub CSS () {
 	 * It reduces eyestrain for me, and energy usage for all:
 	 * https://en.wikipedia.org/wiki/Light-on-dark_color_scheme
 	 */
-	* { background:#000; color:#ccc }
+	* { background:#000 !important; color:#ccc !important }
 
 	/*
 	 * Underlined links add visual noise which make them hard-to-read.
 	 * Use colors to make them stand out, instead.
 	 */
-	a { color:#69f; text-decoration:none }
-	a:visited { color:#96f }
+	a { color:#69f !important; text-decoration:none !important }
+	a:visited { color:#96f !important }
 
-	/* quoted text gets a different color */
-	*.q { color:#09f }
+	/* quoted text in emails gets a different color */
+	*.q { color:#09f !important }
 
 	/*
-	 * 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) 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.
+	 * 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 */
@@ -51,13 +51,15 @@ sub CSS () {
 	.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 }
+	.hl.kwa { color:#ff0 !important }
+	.hl.kwb { color:#0f0 !important }
+	.hl.kwc { color:#ff0 !important }
 	/* .hl.kwd { color:#ccc } */
+
+	/* line-number (unused by public-inbox) */
+	/* .hl.lin { color:#ccc } */
 _
 }
 # end of auto-updated sub
@@ -89,7 +91,14 @@ if (scalar(@ARGV) == 1 && -r __FILE__) {
 	use autodie;
 	open my $ro, '<', $ARGV[0];
 	my $css = do { local $/; <$ro> };
+
+	# indent one level:
 	$css =~ s/^([ \t]*\S)/\t$1/smg;
+
+	# "!important" overrides whatever the BOFH sets:
+	$css =~ s/;/ !important;/sg;
+	$css =~ s/(\w) \}$/$1 !important }/msg;
+
 	open my $rw, '+<', __FILE__;
 	my $out = do { local $/; <$rw> };
 	$out =~ s/^sub CSS.*^_\n\}/sub CSS () {\n\t<<'_'\n${css}_\n}/sm;
-- 
EW


  reply index

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-21 13:36 Default theme Mateusz Loskot
2019-02-22  8:50 ` Eric Wong
2019-02-22 20:39   ` Dmitry Alexandrov
2019-02-23  2:47     ` Eric Wong
2019-02-23 10:56       ` [PATCH 0/2] ensure user CSS always overrides BOFH CSS Eric Wong
2019-02-23 10:56         ` Eric Wong [this message]
2019-02-23 10:56         ` [PATCH 2/2] www: prevent '!important' in BOFH-specified CSS Eric Wong
2019-02-23 19:55       ` Default theme Mateusz Loskot
2019-02-22 20:53   ` Mateusz Loskot
2019-02-23  1:19     ` Dmitry Alexandrov
2019-02-23  2:50       ` Eric Wong
2019-02-23 10:49         ` Eric Wong

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: http://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=20190223105638.15465-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=321942@gmail.com \
    --cc=mateusz@loskot.net \
    --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 http://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