2 # Copyright (C) 2014, Eric Wong <normalperson@yhbt.net> and all contributors
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(https?://[\w+\+\&\?\.\%\;/-]+)!<a\nhref="$1"\n>$1</a>!g;
21 $str =~ s!\e!>!g; # swap escapes back to >
24 '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />',
25 "<title>$title</title>",
26 "</head><body>\n<pre>", $str , '</pre></body></html>';