3 # footnotes Version 0.1 by Thomas Hochstein
5 # This script will convert footnotes in WP-footnotes notation
6 # to MultiMarkDown, i.e. replace "((Text for footnote))" with
7 # "[^1]" and add "[^1]: Text for footnote" at the end of the
8 # text, incrementing the counter each time, or the other way
11 # Copyright (c) 2014 Thomas Hochstein <thh@inter.net>
13 # It can be redistributed and/or modified under the same terms under
14 # which Perl itself is published.
19 use Getopt::Long qw(GetOptions);
21 # read commandline option(s)
23 GetOptions ('t|to=s' => \$OptTo,
24 'f|file=s' => \$OptFile,
25 'h|help' => \&ShowPOD,
26 'V|version' => \&ShowVersion) or exit 1;
28 # read whole article from STDIN or --file
32 open(FILE, "< $OptFile") or die "Can't open $OptFile: $!";
40 # conversion and output
43 if (lc($OptTo) eq 'mmd') {
44 $output = &ConvertToMMD($article);
45 } elsif (lc($OptTo) eq 'wp') {
46 $output = &ConvertToWP($article);
48 print "Please set '--to' to 'mmd' or 'wp'!\n";
55 ################################################################################
62 # match and remove all ((...)),
63 # replacing them with [^n], incrementing n each time
64 while ( $article =~ s/\(\((.+?)\)\)/"[^$counter]"/seo ) {
65 $footnotes .= "[^$counter]: " . $1 . "\n";
69 return "$article\n\n$footnotes\n";
77 # read footnotes in [^n] format
78 while ( $article =~ s/^\[\^$counter\]: (.+)$//m ) {
79 $footnotes[$counter] = $1;
83 # replace footnote plcaeholders with footnote content
85 foreach my $footnote (@footnotes) {
86 $article =~ s/\[\^$counter\]/"(($footnote))"/eg;
90 # remove trailing whitespace
91 $article =~ s/\n+$//g;
97 print "MMD-FootNotes v$VERSION\n";
98 print "Copyright (c) 2014 Thomas Hochstein <thh\@inter.net>\n";
99 print "This program is free software; you may redistribute it ".
100 "and/or modify it under the same terms as Perl itself.\n";