]> Sergey Matveev's repositories - public-inbox.git/blob - Documentation/txt2pre
ipc: drop unused $args from ->ipc_worker_stop
[public-inbox.git] / Documentation / txt2pre
1 #!perl -w
2 # n.b. this is invoked via $(PERL) in makefiles
3 # Copyright (C) all contributors <meta@public-inbox.org>
4 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 #
6 # Stupid script to make HTML from preformatted, utf-8 text versions,
7 # only generating links for http(s).  Markdown does too much
8 # and requires indentation to output preformatted text.
9 use v5.12;
10 use PublicInbox::Linkify;
11 use PublicInbox::Hval qw(ascii_html);
12 my (%xurls, %lei);
13 for (qw[lei(1)
14         lei-add-external(1)
15         lei-add-watch(1)
16         lei-blob(1)
17         lei-config(1)
18         lei-convert(1)
19         lei-daemon(8)
20         lei-daemon-kill(1)
21         lei-daemon-pid(1)
22         lei-edit-search(1)
23         lei-export-kw(1)
24         lei-forget-external(1)
25         lei-forget-mail-sync(1)
26         lei-forget-search(1)
27         lei-import(1)
28         lei-index(1)
29         lei-init(1)
30         lei-inspect(1)
31         lei-lcat(1)
32         lei-ls-external(1)
33         lei-ls-label(1)
34         lei-ls-mail-source(1)
35         lei-ls-mail-sync(1)
36         lei-ls-search(1)
37         lei-ls-watch(1)
38         lei-mail-diff(1)
39         lei-mail-sync-overview(7)
40         lei-overview(7)
41         lei-p2q(1)
42         lei-q(1)
43         lei-rediff(1)
44         lei-refresh-mail-sync(1)
45         lei-reindex(1)
46         lei-rm(1)
47         lei-rm-watch(1)
48         lei-security(7)
49         lei-store-format(5)
50         lei-tag(1)
51         lei-up(1)
52         public-inbox.cgi(1)
53         public-inbox-clone(1)
54         public-inbox-config(5)
55         public-inbox-config(5)
56         public-inbox-convert(1)
57         public-inbox-daemon(8)
58         public-inbox-edit(1)
59         public-inbox-fetch(1)
60         public-inbox-glossary(7)
61         public-inbox-httpd(1)
62         public-inbox-imapd(1)
63         public-inbox-index(1)
64         public-inbox-init(1)
65         public-inbox-learn(1)
66         public-inbox-mda(1)
67         public-inbox-netd(1)
68         public-inbox-nntpd(1)
69         public-inbox-overview(7)
70         public-inbox-pop3d(1)
71         public-inbox-purge(1)
72         public-inbox-v1-format(5)
73         public-inbox-v2-format(5)
74         public-inbox-watch(1)
75         public-inbox-xcpdb(1)
76 ]) {
77         my ($n) = (/([\w\-\.]+)/);
78         $xurls{$_} = "$n.html";
79         $xurls{$n} = "$n.html";
80         /\Alei-(.+?)\(1\)\z/ and $xurls{"lei $1"} = "$n.html";
81 }
82
83 $xurls{'lei/store'} = 'lei-store-format.html';
84
85 for (qw[make(1) flock(2) setrlimit(2) vfork(2) tmpfs(5) inotify(7) unix(7)
86                 syslog(3)]) {
87         my ($n, $s) = (/([\w\-]+)\((\d)\)/);
88         $xurls{$_} = "https://www.man7.org/linux/man-pages/man$s/$n.$s.html";
89 }
90
91 for (qw[git(1)
92         git-am(1)
93         git-apply(1)
94         git-config(1)
95         git-credential(1)
96         git-daemon(1)
97         git-diff(1)
98         git-fast-import(1)
99         git-fetch(1)
100         git-filter-branch(1)
101         git-format-patch(1)
102         git-gc(1)
103         git-http-backend(1)
104         git-imap-send(1)
105         git-init(1)
106         git-send-email(1)
107         gitrepository-layout(5)
108         gitglossary(7)
109 ]) {
110         my ($n) = (/([\w\-\.]+)/);
111         $xurls{$_} = "https://kernel.org/pub/software/scm/git/docs/$n.html"
112 }
113
114 for (qw[
115         sd_listen_fds(3)
116         systemd(1)
117         systemd.unit(5)
118         systemd.socket(5)
119 ]) {
120         my ($n) = (/([\w\-\.]+)/);
121         $xurls{$_} = "https://www.freedesktop.org/software/systemd/man/$n.html";
122 }
123
124 # favor upstream docs if they exist, use manpages.debian.org if they don't
125 $xurls{'netrc(5)'} = 'https://manpages.debian.org/stable/ftp/netrc.5.en.html';
126 $xurls{'mbsync(1)'} =
127         'https://manpages.debian.org/stable/isync/mbsync.1.en.html';
128 $xurls{'offlineimap(1)'} =
129         'https://manpages.debian.org/stable/offlineimap/offlineimap.1.en.html';
130 $xurls{'spamc(1)'} =
131         'https://spamassassin.apache.org/full/3.4.x/doc/spamc.html';
132 $xurls{'grok-pull'} =
133         'https://git.kernel.org/pub/scm/utils/grokmirror/grokmirror.git' .
134         '/tree/man/grok-pull.1.rst';
135 $xurls{'git-filter-repo(1)'} = 'https://github.com/newren/git-filter-repo'.
136                         '/blob/master/Documentation/git-filter-repo.txt';
137 $xurls{'ssoma(1)'} = 'https://ssoma.public-inbox.org/ssoma.txt';
138 $xurls{'cgitrc(5)'} = 'https://git.zx2c4.com/cgit/tree/cgitrc.5.txt';
139 $xurls{'prove(1)'} = 'https://perldoc.perl.org/prove.html';
140 $xurls{'mbox(5)'} = 'https://manpages.debian.org/stable/mutt/mbox.5.en.html';
141 $xurls{'mmdf(5)'} = 'https://manpages.debian.org/stable/mutt/mmdf.5.en.html';
142 $xurls{'mutt(1)'} = 'https://manpages.debian.org/stable/mutt/mutt.1.en.html';
143 $xurls{'torsocks(1)'} =
144         'https://manpages.debian.org/stable/torsocks/torsocks.1.en.html';
145 $xurls{'curl(1)'} = 'https://manpages.debian.org/stable/curl/curl.1.en.html';
146 $xurls{'copydatabase(1)'} =
147  'https://manpages.debian.org/stable/xapian-tools/copydatabase.1.en.html';
148 $xurls{'xapian-compact(1)'} =
149  'https://manpages.debian.org/stable/xapian-tools/xapian-compact.1.en.html';
150 $xurls{'gzip(1)'} = 'https://manpages.debian.org/stable/gzip/gzip.1.en.html';
151 $xurls{'chmod(1)'} =
152         'https://manpages.debian.org/stable/coreutils/chmod.1.en.html';
153 $xurls{'kqueue(2)'} =
154         'https://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2';
155 $xurls{'notmuch(1)'} = 'https://notmuchmail.org/manpages/notmuch-1/';
156 $xurls{'mairix(1)'} =
157         'https://manpages.debian.org/stable/mairix/mairix.1.en.html';
158
159 my $str = do { local $/; <STDIN> };
160 my ($title) = ($str =~ /\A([^\n]+)/);
161 if ($str =~ /^NAME\n\s+([^\n]+)/sm) {
162         # don't link to ourselves
163         $title = $1;
164         if ($title =~ /([\w\.\-]+)/) {
165                 delete $xurls{$1};
166         }
167         if ($title =~ /\blei-([\w\-]+)\b/) {
168                 delete $xurls{"lei $1"};
169         }
170 }
171 $title = ascii_html($title);
172 my $l = PublicInbox::Linkify->new;
173 $str = $l->linkify_1($str);
174 $str = ascii_html($str);
175
176 # longest matches, first
177 my @keys = sort { length($b) <=> length($a) } keys %xurls;
178 my $xkeys = join('|', map { quotemeta } @keys);
179 $str =~ s,(?<![>\w_])($xkeys)(?!(?:[\w<\-]|\.html)),
180         qq(<a\nhref=").$xurls{$1}.qq(">$1).($2//'').'</a>',sge;
181
182 $str = $l->linkify_2($str);
183
184 print '<html><head>',
185   qq(<meta\nhttp-equiv="Content-Type"\ncontent="text/html; charset=utf-8"\n/>),
186   "<title>$title</title>",
187   "</head><body><pre>",  $str , '</pre></body></html>';
188 STDOUT->flush;