#!/usr/bin/env perl use strict; use warnings; use utf8; use feature qw(unicode_strings say); use English '-no_match_vars'; binmode STDOUT, ':encoding(UTF-8)'; binmode STDERR, ':encoding(UTF-8)'; use Text::Markdown 'markdown'; sub slurp { my ($filename) = @_; local $INPUT_RECORD_SEPARATOR = undef; open my $fh, '<', $filename; binmode $fh, ':encoding(UTF-8)'; return <$fh>; } sub main { my $ChangeLog = slurp 'docs/ChangeLog'; $ChangeLog =~ s/(^\s*[^+].*?:\n[ ]*)([+])/$1\n$2/xmsg; say beginning_text() . process_changelog(html_escape($ChangeLog)) . end_text(); } main(); sub process_changelog { my ($in) = @_; my @release_html; # Extracts the text from the 'New in XXXX.XX' to the next 'New in XXXX.XX' # if there are no 'New in' left it extracts to the end of the document. while ($in =~ s/(New in ([\d.]+)(.*?))(New in [\d.]+|$)/$4/s) { my $sec = $3; my $release = $2; print STDERR "$release\n"; my $md_obj = Text::Markdown->new; my $mid = $md_obj->markdown($sec); my $start = <<"END";

$release

END my $end = <<"END";

Download

END my $html = start_enclosing_text($release) . $mid . end_enclosing_text($release); push @release_html, $html; } return join '', @release_html; } # Escapes &, < and > for html sub html_escape { my ($text) = @_; $text =~ s/[&]/&/g; $text =~ s/[<]/</g; $text =~ s/[>]/>/g; return $text; } # The text comes before every version sub start_enclosing_text { my ($release) = @_; my $start = <<"END";

$release

END return $start; } # This text comes after every version sub end_enclosing_text { my ($release) = @_; my $end = <<"END";

Download

END return $end; } # This text begins the html document (only used once). sub beginning_text { <<'END'; MoarVM - A VM for NQP and Rakudo Perl 6
Fork me on GitHub END } # This text ends the html document (only used once). sub end_text { <<'END';
END }