]> Sergey Matveev's repositories - public-inbox.git/blob - Documentation/txt2pre
cb6a76138131a8d0abd3593d013860d523b1f1fa
[public-inbox.git] / Documentation / txt2pre
1 #!/usr/bin/env perl
2 # Copyright (C) 2014-2019 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 #
5 # Stupid script to make HTML from preformatted, utf-8 text versions,
6 # only generating links for http(s).  Markdown does too much
7 # and requires indentation to output preformatted text.
8 use strict;
9 use warnings;
10 use PublicInbox::Linkify;
11 use PublicInbox::Hval qw(ascii_html);
12
13 my $str = eval { local $/; <> };
14 my ($title) = ($str =~ /\A([^\n]+)/);
15 $title = ascii_html($title);
16 my $l = PublicInbox::Linkify->new;
17 $str = $l->linkify_1($str);
18 $str = ascii_html($str);
19 $str = $l->linkify_2($str);
20
21 print '<html><head>',
22   qq(<meta\nhttp-equiv="Content-Type"\ncontent="text/html; charset=utf-8"\n/>),
23   "<title>$title</title>",
24   "</head><body><pre>",  $str , '</pre></body></html>';
25 STDOUT->flush;
26
27 # keep mtime on website consistent so clients can cache
28 if (-f STDIN && -f STDOUT) {
29         my @st = stat(STDIN);
30         utime($st[8], $st[9], \*STDOUT);
31 }