summaryrefslogtreecommitdiff
path: root/mediawiki-matter
diff options
context:
space:
mode:
Diffstat (limited to 'mediawiki-matter')
-rwxr-xr-xmediawiki-matter29
1 files changed, 29 insertions, 0 deletions
diff --git a/mediawiki-matter b/mediawiki-matter
new file mode 100755
index 0000000..584e5f4
--- /dev/null
+++ b/mediawiki-matter
@@ -0,0 +1,29 @@
+#!/usr/bin/perl
+
+# separate frontmatter pieces from mainmatter
+
+use warnings;
+use strict;
+
+use Path::Tiny;
+use HTML::HTML5::Entities;
+
+my $infile = shift;
+my $outfile = shift || $infile;
+
+$_ = path($infile)->slurp_utf8;
+
+s|^((?:.*?\n)?)(= Preface(?:(?!\n=).)*\n)(=.*)$|$1$3|s;
+path('preface.mw')->spew_utf8($2);
+
+s|^((?:.*?\n)?)(= Foreword(?:(?!\n=).)*\n)(=.*)$|$1$3|s;
+path('foreword.mw')->spew_utf8($2);
+
+s|^((?:.*?\n)?)(= Copyright(?:(?!\n=).)*\n)(=.*)$|$1$3|s;
+path('copyright.mw')->spew_utf8($2);
+
+s|^((?:.*?\n)?)(= Table of Contents(?:(?!\n=).)*\n)(=.*)$|$1$3|s;
+
+path($outfile)->spew_utf8($_);
+
+1;