[PATCH 2/2] devel: added newssplit.pl for splitting NEWS for markdown processing.

Tomi Ollila tomi.ollila at iki.fi
Wed Feb 1 07:22:50 PST 2012


devel/newssplit.pl splits NEWS file to separate files per release.

In addition to splitting it changes lines starting with '*' to start
with '###' (markdown for h3) and concatenates continuing non-empty
lines to the same line; markdown does now allow (long) header line
to be split into multiple lines -- such long lines would look ugly
when reading the original NEWS file in text format.
---
See http://notmuchmail.org/news/ (as of 2012-02-01) to see current
output
 devel/newssplit.pl |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)
 create mode 100755 devel/newssplit.pl

diff --git a/devel/newssplit.pl b/devel/newssplit.pl
new file mode 100755
index 0000000..c1a0b26
--- /dev/null
+++ b/devel/newssplit.pl
@@ -0,0 +1,56 @@
+#!/usr/bin/perl
+# Author: Tomi Ollila
+# License: same as notmuch
+
+# This program is used to split NEWS file to separate (mdwn) files 
+# for notmuch wiki. Example run:
+#
+# $ ./devel/newssplit.pl NEWS ../notmuch-wiki/news
+
+use strict;
+use warnings;
+
+die "$0 <source-file> <destination-directory>\n" unless @ARGV == 2;
+
+die "'$ARGV[0]': no such file\n" unless -f $ARGV[0];
+die "'$ARGV[1]': no such directory\n" unless -d $ARGV[1];
+
+open I, '<', $ARGV[0] or die "Cannot open '$ARGV[0]': $!\n";
+
+open O, '>', '/dev/null' or die $!;
+my @emptylines = ();
+print "\nWriting to $ARGV[1]: ";
+while (<I>)
+{
+    # The date part in regex regognizes wip version dates like: (201x-xx-xx).
+    if (/^Notmuch\s+(\S+)\s+\((\w\w\w\w-\w\w-\w\w)\)/) {
+	# open O... autocloses previously opened file.
+	open O, '>', "$ARGV[1]/release-$1.mdwn" or die $!;
+	print " release-$1.mdwn...";
+	print O "[[!meta date=\"$2\"]]\n\n";
+	@emptylines = ();
+    }
+    # buffer "trailing" empty lines -- dropped at end of file. 
+    push(@emptylines, $_), next if s/^\s*$/\n/;
+    if (@emptylines) {
+	print O @emptylines;
+	@emptylines = ();
+    }
+    # convert top-level list item to level 4 header.
+    if (s/^\*\s+//) {
+	chomp;
+	my @l = $_;
+	while (<I>) {
+	    last if /^\s*$/;
+	    chomp; s/^\s+//;
+	    push @l, $_;
+	}
+	print O "### ", (join ' ', @l), "\n";
+	@emptylines = ( "\n" );
+	next;
+    }
+
+    print O $_;
+}
+print "\ndone.\n";
+close O;
-- 
1.7.6.5



More information about the notmuch mailing list