aboutsummaryrefslogtreecommitdiff
path: root/ikiwiki-transition
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-01-30 17:22:59 -0500
committerJoey Hess <joey@kodama.kitenet.net>2008-01-30 17:22:59 -0500
commit61ffa4a81653bc499abb358244dba102323abc99 (patch)
tree90189e2ae2e7d9bdeff09b53529c47de3e814bc0 /ikiwiki-transition
parent4c18058dfb52ae32c55e27efda380f1df0a4c872 (diff)
downloadikiwiki-61ffa4a81653bc499abb358244dba102323abc99.tar
ikiwiki-61ffa4a81653bc499abb358244dba102323abc99.tar.gz
rename ikiwiki-prefix-directives into ikiwiki-transition
If we have transitions of this sort in the future, this program will hopefully be used to handle them too.
Diffstat (limited to 'ikiwiki-transition')
-rwxr-xr-xikiwiki-transition66
1 files changed, 66 insertions, 0 deletions
diff --git a/ikiwiki-transition b/ikiwiki-transition
new file mode 100755
index 000000000..1fd23cec5
--- /dev/null
+++ b/ikiwiki-transition
@@ -0,0 +1,66 @@
+#!/usr/bin/perl -i
+use warnings;
+use strict;
+
+my $regex = qr{
+ (\\?) # 1: escape?
+ \[\[(!?) # directive open; 2: optional prefix
+ ([-\w]+) # 3: command
+ ( # 4: the parameters (including initial whitespace)
+ \s+
+ (?:
+ (?:[-\w]+=)? # named parameter key?
+ (?:
+ """.*?""" # triple-quoted value
+ |
+ "[^"]+" # single-quoted value
+ |
+ [^\s\]]+ # unquoted value
+ )
+ \s* # whitespace or end
+ # of directive
+ )
+ *) # 0 or more parameters
+ \]\] # directive closed
+}sx;
+
+sub handle_directive {
+ my $escape = shift;
+ my $prefix = shift;
+ my $directive = shift;
+ my $args = shift;
+
+ if (length $escape) {
+ return "${escape}[[${prefix}${directive}${args}]]"
+ }
+ if ($directive =~ m/^(if|more|table|template|toggleable)$/) {
+ $args =~ s{$regex}{handle_directive($1, $2, $3, $4)}eg;
+ }
+ return "[[!${directive}${args}]]"
+}
+
+sub prefix_directives {
+ $/=undef; # process whole files at once
+
+ while (<>) {
+ s{$regex}{handle_directive($1, $2, $3, $4)}eg;
+ print;
+ }
+}
+
+sub usage {
+ print STDERR "Usage: ikiwiki-transition type file ...\n";
+ print STDERR "Currently supported transition types:\n";
+ print STDERR " prefix_directives\n";
+ exit 1;
+}
+
+usage() unless @ARGV;
+
+my $mode=shift;
+if ($mode eq 'prefix_directives') {
+ prefix_directives(@ARGV);
+}
+else {
+ usage();
+}