Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use strict;
- use warnings;
- my $cvt;
- my $lookahead;
- my $do_categories = 1;
- my $categories_stop_at_ver = lc shift;
- while(<STDIN>)
- {
- $cvt = 1;
- # NOTE: see hack below.
- $do_categories = 0 if $do_categories &&
- /^Version ([^:]+):?$/i &&
- lc $1 eq $categories_stop_at_ver;
- # add ## to the beginning of any line starting with "Version"
- s/^(Version)/## $1/i and next;
- # HACK: the code below generates Markdown that doesn't look great when
- # rendered by GitHub if the subsection is preceded or followed
- # by root-level items. So just skip the insanity after a point
- # defined in the command line.
- # add ### to the beginning of any lines starting with " *" (one preceding space)
- if ($do_categories && /^ \*\s*/) {
- # Avoid breaking ancient changelog entries where there many versions
- # have root items that do not denote a subsection.
- $lookahead = <STDIN>;
- if (defined($lookahead) && $lookahead =~ /^ \*/) {
- s/^ \*\s*/ ### /;
- next;
- }
- }
- $cvt = 0;
- }
- continue {
- # Remove trailing ":" from any lines where the above conversions are preformed
- $cvt and s/:\s*$/\n/;
- print;
- # NOTE: dead code (see hack above).
- if (defined($lookahead)) {
- $_ = $lookahead;
- undef $lookahead;
- redo;
- }
- }
Add Comment
Please, Sign In to add comment