X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=Documentation%2Ftxt2pre;h=7bc31d23d5649794ee4e84ea8ab2b76d7675f059;hb=69b5ab18a594fa434d79cacee35c4d9a0df7b55c;hp=ef6a4f3557395825d05fc5818ba56696367ec40e;hpb=e012d02ca21ddd01864c683e9cec318190abb047;p=public-inbox.git
diff --git a/Documentation/txt2pre b/Documentation/txt2pre
index ef6a4f35..7bc31d23 100755
--- a/Documentation/txt2pre
+++ b/Documentation/txt2pre
@@ -1,28 +1,160 @@
#!/usr/bin/env perl
-# Copyright (C) 2014-2015 all contributors
-# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
+# Copyright (C) 2014-2021 all contributors
+# License: AGPL-3.0+
#
# Stupid script to make HTML from preformatted, utf-8 text versions,
# only generating links for http(s). Markdown does too much
# and requires indentation to output preformatted text.
use strict;
use warnings;
-use CGI qw/escapeHTML/;
-use Encode qw/encode/;
-my $str = eval { local $/; <> };
-$str = escapeHTML($str);
-$str = encode('us-ascii', $str, Encode::HTMLCREF);
+use PublicInbox::Linkify;
+use PublicInbox::Hval qw(ascii_html);
+my %xurls;
+for (qw[lei(1)
+ lei-add-external(1)
+ lei-blob(1)
+ lei-config(1)
+ lei-convert(1)
+ lei-daemon-kill(1)
+ lei-daemon-pid(1)
+ lei-edit-search(1)
+ lei-forget-external(1)
+ lei-forget-search(1)
+ lei-import(1)
+ lei-index(1)
+ lei-init(1)
+ lei-lcat(1)
+ lei-ls-external(1)
+ lei-ls-label(1)
+ lei-ls-mail-sync(1)
+ lei-ls-search(1)
+ lei-overview(7)
+ lei-p2q(1)
+ lei-q(1)
+ lei-rediff(1)
+ lei-rm(1)
+ lei-store-format(5)
+ lei-security(7)
+ lei-tag(1)
+ lei-up(1)
+ public-inbox.cgi(1)
+ public-inbox-clone(1)
+ public-inbox-config(5)
+ public-inbox-config(5)
+ public-inbox-convert(1)
+ public-inbox-daemon(8)
+ public-inbox-edit(1)
+ public-inbox-fetch(1)
+ public-inbox-glossary(7)
+ public-inbox-httpd(1)
+ public-inbox-imapd(1)
+ public-inbox-index(1)
+ public-inbox-init(1)
+ public-inbox-learn(1)
+ public-inbox-mda(1)
+ public-inbox-nntpd(1)
+ public-inbox-overview(7)
+ public-inbox-purge(1)
+ public-inbox-v1-format(5)
+ public-inbox-v2-format(5)
+ public-inbox-watch(1)
+ public-inbox-xcpdb(1)
+]) {
+ my ($n) = (/([\w\-\.]+)/);
+ $xurls{$_} = "$n.html";
+ $xurls{$n} = "$n.html";
+}
+
+for (qw[copydatabase(1) xapian-compact(1)]) {
+ my ($n) = (/([\w\-\.]+)/);
+ $xurls{$_} = ".$n.1.html"
+}
+
+for (qw[make(1) flock(2) setrlimit(2) vfork(2) tmpfs(5)]) {
+ my ($n, $s) = (/([\w\-]+)\((\d)\)/);
+ $xurls{$_} = "http://www.man7.org/linux/man-pages/man$s/$n.$s.html";
+}
+
+for (qw[git(1)
+ git-am(1)
+ git-apply(1)
+ git-config(1)
+ git-credential(1)
+ git-daemon(1)
+ git-diff(1)
+ git-fast-import(1)
+ git-fetch(1)
+ git-filter-branch(1)
+ git-format-patch(1)
+ git-gc(1)
+ git-http-backend(1)
+ git-imap-send(1)
+ git-init(1)
+ git-send-email(1)
+ gitrepository-layout(5)
+]) {
+ my ($n) = (/([\w\-\.]+)/);
+ $xurls{$_} = "https://kernel.org/pub/software/scm/git/docs/$n.html"
+}
+
+for (qw[
+ sd_listen_fds(3)
+ systemd(1)
+ systemd.unit(5)
+ systemd.socket(5)
+]) {
+ my ($n) = (/([\w\-\.]+)/);
+ $xurls{$_} = "https://www.freedesktop.org/software/systemd/man/$n.html";
+}
+
+$xurls{'netrc(5)'} = 'https://manpages.debian.org/stable/ftp/netrc.5.en.html';
+$xurls{'mbsync(1)'} =
+ 'https://manpages.debian.org/stable/isync/mbsync.1.en.html';
+$xurls{'offlineimap(1)'} =
+ 'https://manpages.debian.org/stable/offlineimap/offlineimap.1.en.html';
+$xurls{'spamc(1)'} =
+ 'https://spamassassin.apache.org/full/3.4.x/doc/spamc.html';
+$xurls{'grok-pull'} =
+ 'https://git.kernel.org/pub/scm/utils/grokmirror/grokmirror.git' .
+ '/tree/man/grok-pull.1.rst';
+$xurls{'git-filter-repo(1)'} = 'https://github.com/newren/git-filter-repo'.
+ '/blob/master/Documentation/git-filter-repo.txt';
+$xurls{'ssoma(1)'} = 'https://ssoma.public-inbox.org/ssoma.txt';
+$xurls{'cgitrc(5)'} = 'https://git.zx2c4.com/cgit/tree/cgitrc.5.txt';
+$xurls{'prove(1)'} = 'https://perldoc.perl.org/prove.html';
+$xurls{'mbox(5)'} = 'https://manpages.debian.org/stable/mutt/mbox.5.en.html';
+$xurls{'mmdf(5)'} = 'https://manpages.debian.org/stable/mutt/mmdf.5.en.html';
+
+my $str = do { local $/; };
my ($title) = ($str =~ /\A([^\n]+)/);
+if ($str =~ /^NAME\n\s+([^\n]+)/sm) {
+ # don't link to ourselves
+ $title = $1;
+ if ($title =~ /([\w\.\-]+)/) {
+ delete $xurls{$1};
+ }
+}
+$title = ascii_html($title);
+my $l = PublicInbox::Linkify->new;
+$str = $l->linkify_1($str);
+$str = ascii_html($str);
-# temporarily swap > for escape so our s!! to add href works.
-# there's probably a way to do this with only a single s!! ...
-$str =~ s!>!\e!g;
-$str =~ s!\b((nntp|ftp|https?)://[\w+\+\&\?\.\%\;/#-]+)!$1!g;
+# longest matches, first
+my @keys = sort { length($b) <=> length($a) } keys %xurls;
+my $xkeys = join('|', map { quotemeta } @keys);
+$str =~ s,(?\w_])($xkeys)(?!(?:[\w<\-]|\.html)),
+ qq($1).($2//'').'',sge;
-$str =~ s!\e!>!g; # swap escapes back to >
+$str = $l->linkify_2($str);
print '',
- '',
+ qq(),
"$title",
- "\n", $str , '
';
+ "", $str , '