2 # Copyright (C) 2014-2015 all contributors <meta@public-inbox.org>
3 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
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.
10 use CGI qw/escapeHTML/;
11 use Encode qw/encode/;
12 my $str = eval { local $/; <> };
13 $str = escapeHTML($str);
14 $str = encode('us-ascii', $str, Encode::HTMLCREF);
15 my ($title) = ($str =~ /\A([^\n]+)/);
17 # temporarily swap > for escape so our s!! to add href works.
18 # there's probably a way to do this with only a single s!! ...
20 $str =~ s!\b((nntp|ftp|https?)://[\w+\+\&\?\.\%\;/#-]+)!<a
23 $str =~ s!\e!>!g; # swap escapes back to >
26 '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />',
27 "<title>$title</title>",
28 "</head><body>\n<pre>", $str , '</pre></body></html>';