]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WwwText.pm
wwwtext: inline sample CSS and use highlight
[public-inbox.git] / lib / PublicInbox / WwwText.pm
index b8beb97c6d5983e9c319a2f7733a4e232fc7f884..adadc37aab3da1f32ee40a7eb0687444281b9696 100644 (file)
@@ -1,7 +1,7 @@
-# Copyright (C) 2016 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-#
-# serves the /$INBOX/_/* endpoints from :text/* of the git tree
+
+# used for displaying help texts and other non-mail content
 package PublicInbox::WwwText;
 use strict;
 use warnings;
 package PublicInbox::WwwText;
 use strict;
 use warnings;
@@ -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';
 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
 
 # /$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;
 
 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 ($$) {
 }
 
 sub _srch_prefix ($$) {
@@ -88,9 +98,33 @@ sub _srch_prefix ($$) {
        1;
 }
 
        1;
 }
 
+sub _colors_help ($$) {
+       my ($ctx, $txt) = @_;
+       my $ibx = $ctx->{-inbox};
+       my $env = $ctx->{env};
+       my $base_url = $ibx->base_url($env);
+       $$txt .= "color customization for $base_url\n";
+       $$txt .= <<EOF;
+
+public-inbox provides a stable set of CSS classes for users to
+customize colors for highlighting diffs and code.
+
+Users of browsers such as dillo, Firefox, or some browser
+extensions may start by downloading the following sample CSS file
+to control the colors they see:
+
+       ${base_url}userContent.css
+
+CSS sample
+----------
+```css
+EOF
+       $$txt .= PublicInbox::UserContent::sample($ibx, $env) . "```\n";
+}
 
 sub _default_text ($$$) {
        my ($ctx, $key, $txt) = @_;
 
 sub _default_text ($$$) {
        my ($ctx, $key, $txt) = @_;
+       return _colors_help($ctx, $txt) if $key eq 'color';
        return if $key ne 'help'; # TODO more keys?
 
        my $ibx = $ctx->{-inbox};
        return if $key ne 'help'; # TODO more keys?
 
        my $ibx = $ctx->{-inbox};
@@ -134,7 +168,7 @@ search
     in other search engines.
 
     We also support search prefixes to limit the scope of the
     in other search engines.
 
     We also support search prefixes to limit the scope of the
-    search to certain fields using prefixes.
+    search to certain fields.
 
     Prefixes supported in this installation include:
 
 
     Prefixes supported in this installation include:
 
@@ -142,6 +176,10 @@ EOF
                _srch_prefix($srch, $txt);
 
                $$txt .= <<EOF;
                _srch_prefix($srch, $txt);
 
                $$txt .= <<EOF;
+
+    Most prefixes are probabilistic, meaning they support stemming
+    and wildcards ('*').  Ranges (such as 'd:') and boolean prefixes
+    do not support stemming or wildcards.
     The upstream Xapian query parser documentation fully explains
     the query syntax:
 
     The upstream Xapian query parser documentation fully explains
     the query syntax:
 
@@ -178,6 +216,10 @@ message threading
        $WIKI_URL/Atom_(standard)
        https://tools.ietf.org/html/rfc4287
 
        $WIKI_URL/Atom_(standard)
        https://tools.ietf.org/html/rfc4287
 
+      Atom Threading Extensions (RFC4685) is supported:
+
+       https://tools.ietf.org/html/rfc4685
+
     Finally, the gzipped mbox for a thread is available for
     downloading and importing into your favorite mail client:
 
     Finally, the gzipped mbox for a thread is available for
     downloading and importing into your favorite mail client: