diff options
author | Josh Triplett <josh@freedesktop.org> | 2008-01-27 16:13:54 -0800 |
---|---|---|
committer | Josh Triplett <josh@freedesktop.org> | 2008-01-27 16:14:38 -0800 |
commit | 1b03a06c8c0dbf59469ff30d09a0c9c3051e0b00 (patch) | |
tree | 06f20b766475a98f7881aa962f0c8a494c87908b /ikiwiki-prefix-directives | |
parent | fafb2edaa7aeb1293e716fa96f087cb713f4a70a (diff) |
Add new preprocessor directive syntax¸ using a '!' prefix.
Add a prefix_directives option to the setup file to turn this syntax
on; currently defaults to false, for backward compatibility. Support
optional '!' prefix even with prefix_directives off, and use that in
the underlay to support either setting of prefix_directives. Add NEWS
entry with migration information.
Diffstat (limited to 'ikiwiki-prefix-directives')
-rwxr-xr-x | ikiwiki-prefix-directives | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/ikiwiki-prefix-directives b/ikiwiki-prefix-directives new file mode 100755 index 000000000..d35c41f30 --- /dev/null +++ b/ikiwiki-prefix-directives @@ -0,0 +1,44 @@ +#!/usr/bin/perl -i +undef $/; # process whole files at once + +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}]]" +} + +while (<>) { + s{$regex}{handle_directive($1, $2, $3, $4)}eg; + print; +} |