2 # Copyright (C) 2015-2020 all contributors <cmogstored-public@yhbt.net>
3 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-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/;
14 open my $fh, '<', $file or die "failed to open $file: $!\n";
18 $str = eval { local $/; <> };
27 $str =~ s/([<>&'"])/$xhtml_map{$1}/ge;
28 $str = encode
('us-ascii', $str, Encode
::HTMLCREF
);
29 my ($title) = ($str =~ /\A([^\n]+)\n[^a-zA-Z]*\n/s);
31 unless (defined $title) {
33 $title =~ s
,\A
[^/]*/,,;
34 $title = "cmogstored - $title";
37 # temporarily swap > for escape so our s!! to add href works.
38 # there's probably a way to do this with only a single s!! ...
40 $str =~ s!\b((nntps?|ftp|https?|imaps?)://[\w+\+\&\?\.\%\;/#=\!\@-]+)!<a
43 $str =~ s!\e!>!g; # swap escapes back to >
46 '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />',
47 "<title>$title</title>",
48 "</head><body>\n<pre>", $str , '</pre></body></html>';