2 # Copyright (C) 2014-2016 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <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 Encode qw/encode/;
11 my $str = eval { local $/; <> };
19 $str =~ s/([<>&'"])/$xhtml_map{$1}/ge;
20 $str = encode('us-ascii', $str, Encode::HTMLCREF);
21 my ($title) = ($str =~ /\A([^\n]+)/);
23 # temporarily swap > for escape so our s!! to add href works.
24 # there's probably a way to do this with only a single s!! ...
26 $str =~ s!\b((nntp|ftp|https?)://[\w+\+\&\?\.\%\;/#-]+)!<a
29 $str =~ s!\e!>!g; # swap escapes back to >
32 '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />',
33 "<title>$title</title>",
34 "</head><body>\n<pre>", $str , '</pre></body></html>';