]> Sergey Matveev's repositories - public-inbox.git/blob - Documentation/txt2pre
public-inbox 1.1.0-pre1
[public-inbox.git] / Documentation / txt2pre
1 #!/usr/bin/env perl
2 # Copyright (C) 2014-2018 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 = $ENV{TITLE};
15 ($title) = ($str =~ /\A([^\n]+)/) unless $title;
16 $title = ascii_html($title);
17 my $l = PublicInbox::Linkify->new;
18 $str = $l->linkify_1($str);
19 $str = ascii_html($str);
20 $str = $l->linkify_2($str);
21
22 print '<html><head>',
23   qq(<meta\nhttp-equiv="Content-Type"\ncontent="text/html; charset=utf-8"\n/>),
24   "<title>$title</title>",
25   "</head><body><pre>",  $str , '</pre></body></html>';