Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
sub build_value { # convert and build MT template tags within a passed value. my ($ctx, $value, $case_sensitive) = @_; # within a value argument, you can use MT tags, but with # square brackets instead of angle brackets and single quotes # instead of double quotes; literal square brackets and single # quotes must be escaped with a backslash # convert non-escaped []' $value =~ s/(?<!\\)\[/</g; $value =~ s/(?<!\\)\]/>/g; $value =~ s/(?<!\\)'/"/g; # de-escape escaped []' $value =~ s/\\([\[\]'])/$1/g; # any MT tags? if ($value =~ /<MT/) { my $builder = $ctx->stash('builder'); my $tok = $builder->compile($ctx, $value); $value = $builder->build($ctx, $tok); return $ctx->error($builder->errstr) unless defined($value); } $value = lc($value) unless ($case_sensitive); return $value; }
This paste will be private.
From the Design Piracy series on my blog: