2 undef $/; # process whole files at once
6 \[\[(!?) # directive open; 2: optional prefix
8 ( # 4: the parameters (including initial whitespace)
11 (?:[-\w]+=)? # named parameter key?
13 """.*?""" # triple-quoted value
15 "[^"]+" # single-quoted value
17 [^\s\]]+ # unquoted value
19 \s* # whitespace or end
22 *) # 0 or more parameters
23 \]\] # directive closed
26 sub handle_directive($$$$) {
29 my $directive = shift;
33 return "${escape}[[${prefix}${directive}${args}]]"
35 if ($directive =~ m/^(if|more|table|template|toggleable)$/) {
36 $args =~ s{$regex}{handle_directive($1, $2, $3, $4)}eg;
38 return "[[!${directive}${args}]]"
42 s{$regex}{handle_directive($1, $2, $3, $4)}eg;