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 # The date part in regex recognizes wip version dates like: (201x-xx-xx).
36 if (/^Notmuch\s+(\S+)\s+\((\w\w\w\w-\w\w-\w\w)\)\s*$/) {
37 # open O... autocloses previously opened file.
38 open O, '>', "$ARGV[1]/release-$1.mdwn" or die $!;
39 print "+ release-$1.mdwn...\n";
40 print O "[[!meta date=\"$2\"]]\n\n";
44 last if /^<!--\s*$/; # Local variables block at the end (as of now).
46 # Buffer "trailing" empty lines -- dropped at end of file.
47 push(@emptylines, $_), next if s/^\s*$/\n/;
53 # Convert '*' to '`*`' and "*" to "`*`" so that * is not considered
54 # as starting emphasis character there. We're a bit opportunistic
55 # there -- some single * does not cause problems and, on the other
56 # hand, this would not regognize already 'secured' *:s.
57 s/'[*]'/'`*`'/g; s/"[*]"/"`*`"/g;
59 # Convert nonindented lines that aren't already headers or
60 # don't contain periods (.) or '!'s to level 4 header.
68 #$cln = 0 if /^---/ or /^===/; # used for debugging.
69 $tbc = 0 if /[.!]\s/ or /^---/ or /^===/;
74 print O "### ", (join ' ', @l), "\n";
77 #print "$ARGV[0]:$cln: skip level 4 header conversion\n" if $cln;
78 print O (join "\n", @l), "\n";
80 @emptylines = ( "\n" );
84 # Markdown doc specifies that list item may have paragraphs if those
85 # are indented by 4 spaces (or a tab) from current list item marker
86 # indentation (paragraph meaning there is empty line in between).
87 # If there is empty line and next line is not indented 4 chars then
88 # that should end the above list. This doesn't happen in all markdown
90 # In our NEWS case this problem exists in release 0.6 documentation.
91 # It can be avoided by removing 2 leading spaces in lines that are not
92 # list items and requiring all that indents are 0, 2, and 4+ (to make
94 # Nested lists are supported but one needs to be more careful with
95 # markup there (as the hack below works only on first level).
97 s/^[ ][ ]// unless /^[ ][ ](?:[\s*+-]|\d+\.)\s/;