diff options
author | Eric Wong <e@80x24.org> | 2015-11-20 01:56:27 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-11-20 02:18:28 +0000 |
commit | c0da4eb6eeb4bec9b70aede7176a91f536e5bbe8 (patch) | |
tree | c8466e7cf67194b01b28b91409528dd00bb2f92b /build-aux/txt2pre | |
parent | fd0a3959bb678e94719bfa454c8b3742635ca98c (diff) | |
download | cmogstored-c0da4eb6eeb4bec9b70aede7176a91f536e5bbe8.tar.gz |
Generate pre-formatted HTML which gives us a consistent visual style with our mailing list archives and enhance linkability. <a>, <pre>, and <title> are among the few useful HTML tags I'll use :P Drop the AUTHORS file, it's pointless maintenance task and users can just look at git history instead (and honestly, I have zero interest in recognition; I only use my real name to deter GPL violations).
Diffstat (limited to 'build-aux/txt2pre')
-rwxr-xr-x | build-aux/txt2pre | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/build-aux/txt2pre b/build-aux/txt2pre new file mode 100755 index 0000000..bc42952 --- /dev/null +++ b/build-aux/txt2pre @@ -0,0 +1,43 @@ +#!/usr/bin/env perl +# Copyright (C) 2015 all contributors <cmogstored-public@bogomips.org> +# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# +# Stupid script to make HTML from preformatted, utf-8 text versions, +# only generating links for http(s). Markdown does too much +# and requires indentation to output preformatted text. +use strict; +use warnings; +use CGI qw/escapeHTML/; +use Encode qw/encode/; +my $file = shift; +my $str; +if (defined $file) { + open my $fh, '<', $file or die "failed to open $file: $!\n"; + local $/; + $str = <$fh>; +} else { + $str = eval { local $/; <> }; +} + +$str = escapeHTML($str); +$str = encode('us-ascii', $str, Encode::HTMLCREF); +my ($title) = ($str =~ /\A([^\n]+)\n[^a-zA-Z]*\n/s); + +unless (defined $title) { + $title = $file; + $title =~ s,\A[^/]*/,,; + $title = "cmogstored - $title"; +} + +# temporarily swap > for escape so our s!! to add href works. +# there's probably a way to do this with only a single s!! ... +$str =~ s!>!\e!g; +$str =~ s!\b((nntp|ftp|https?)://[\w+\+\&\?\.\%\;/#-]+)!<a +href="$1"\n>$1</a>!g; + +$str =~ s!\e!>!g; # swap escapes back to > + +print '<html><head>', + '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />', + "<title>$title</title>", + "</head><body>\n<pre>", $str , '</pre></body></html>'; |