Guest User

Untitled

a guest
Mar 21st, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. my $cvt;
  7. my $lookahead;
  8.  
  9. my $do_categories = 1;
  10. my $categories_stop_at_ver = lc shift;
  11.  
  12. while(<STDIN>)
  13. {
  14. $cvt = 1;
  15.  
  16. # NOTE: see hack below.
  17. $do_categories = 0 if $do_categories &&
  18. /^Version ([^:]+):?$/i &&
  19. lc $1 eq $categories_stop_at_ver;
  20.  
  21. # add ## to the beginning of any line starting with "Version"
  22. s/^(Version)/## $1/i and next;
  23.  
  24. # HACK: the code below generates Markdown that doesn't look great when
  25. # rendered by GitHub if the subsection is preceded or followed
  26. # by root-level items. So just skip the insanity after a point
  27. # defined in the command line.
  28.  
  29. # add ### to the beginning of any lines starting with " *" (one preceding space)
  30. if ($do_categories && /^ \*\s*/) {
  31. # Avoid breaking ancient changelog entries where there many versions
  32. # have root items that do not denote a subsection.
  33.  
  34. $lookahead = <STDIN>;
  35.  
  36. if (defined($lookahead) && $lookahead =~ /^ \*/) {
  37. s/^ \*\s*/ ### /;
  38. next;
  39. }
  40. }
  41.  
  42. $cvt = 0;
  43. }
  44. continue {
  45. # Remove trailing ":" from any lines where the above conversions are preformed
  46. $cvt and s/:\s*$/\n/;
  47.  
  48. print;
  49.  
  50. # NOTE: dead code (see hack above).
  51. if (defined($lookahead)) {
  52. $_ = $lookahead;
  53. undef $lookahead;
  54. redo;
  55. }
  56. }
Add Comment
Please, Sign In to add comment