4 # License: same as notmuch
6 # This program is used to split NEWS file to separate (mdwn) files
7 # for notmuch wiki. Example run:
9 # $ ./devel/news2wiki.pl NEWS ../notmuch-wiki/news
11 # In case taken into more generic use, modify these comments and examples.
17 warn "\n$0 <source-file> <destination-directory>\n\n";
18 warn "Example: ./devel/news2wiki.pl NEWS ../notmuch-wiki/news\n\n";
22 die "'$ARGV[0]': no such file\n" unless -f $ARGV[0];
23 die "'$ARGV[1]': no such directory\n" unless -d $ARGV[1];
25 open I, '<', $ARGV[0] or die "Cannot open '$ARGV[0]': $!\n";
27 open O, '>', '/dev/null' or die $!;
30 print "\nWriting to $ARGV[1]:\n";
33 warn "$ARGV[0]:$.: tab(s) in line!\n" if /\t/;
34 warn "$ARGV[0]:$.: trailing whitespace\n" if /\s\s$/;
35 if (/^Notmuch\s+(\S+)\s+\((\d\d\d\d-\d\d-\d\d|UNRELEASED)\)\s*$/) {
36 # open O... autocloses previously opened file.
37 open O, '>', "$ARGV[1]/release-$1.mdwn" or die $!;
38 print "+ release-$1.mdwn...\n";
39 print O "[[!meta date=\"$2\"]]\n\n";
43 last if /^<!--\s*$/; # Local variables block at the end (as of now).
45 # Buffer "trailing" empty lines -- dropped at end of file.
46 push(@emptylines, $_), next if s/^\s*$/\n/;
52 # Convert '*' to '`*`' and "*" to "`*`" so that * is not considered
53 # as starting emphasis character there. We're a bit opportunistic
54 # there -- some single * does not cause problems and, on the other
55 # hand, this would not regognize already 'secured' *:s.
56 s/'[*]'/'`*`'/g; s/"[*]"/"`*`"/g;
58 # Convert nonindented lines that aren't already headers or
59 # don't contain periods (.) or '!'s to level 4 header.
67 #$cln = 0 if /^---/ or /^===/; # used for debugging.
68 $tbc = 0 if /[.!]\s/ or /^---/ or /^===/;
73 print O "### ", (join ' ', @l), "\n";
76 #print "$ARGV[0]:$cln: skip level 4 header conversion\n" if $cln;
77 print O (join "\n", @l), "\n";
79 @emptylines = ( "\n" );
83 # Markdown doc specifies that list item may have paragraphs if those
84 # are indented by 4 spaces (or a tab) from current list item marker
85 # indentation (paragraph meaning there is empty line in between).
86 # If there is empty line and next line is not indented 4 chars then
87 # that should end the above list. This doesn't happen in all markdown
89 # In our NEWS case this problem exists in release 0.6 documentation.
90 # It can be avoided by removing 2 leading spaces in lines that are not
91 # list items and requiring all that indents are 0, 2, and 4+ (to make
93 # Nested lists are supported but one needs to be more careful with
94 # markup there (as the hack below works only on first level).
96 s/^[ ][ ]// unless /^[ ][ ](?:[\s*+-]|\d+\.)\s/;