diff --git a/plugins/ExtraTags/config.yaml b/plugins/ExtraTags/config.yaml index f39a680..3f05228 100644 --- a/plugins/ExtraTags/config.yaml +++ b/plugins/ExtraTags/config.yaml @@ -3,7 +3,7 @@ key: Extra Tags description: A collection of extra template tags that might be helpful. author_name: Byrne Reese, Endevver LLC author_link: http://www.endevver.com/ -version: 1.15 +version: 1.17 tags: block: @@ -34,3 +34,5 @@ tags: handler: $ExtraTags::ExtraTags::Plugin::mod_nice_size n_words: handler: $ExtraTags::ExtraTags::Plugin::mod_n_words + encode_json: + handler: $ExtraTags::ExtraTags::Plugin::mod_encode_json diff --git a/plugins/ExtraTags/lib/ExtraTags/Plugin.pm b/plugins/ExtraTags/lib/ExtraTags/Plugin.pm index 5a9f195..7d814ef 100644 --- a/plugins/ExtraTags/lib/ExtraTags/Plugin.pm +++ b/plugins/ExtraTags/lib/ExtraTags/Plugin.pm @@ -206,7 +206,7 @@ sub mod_n_words { my ($str, $val, $ctx) = @_; return '' unless defined $str; my $elip; - ($val,$elip) = ($val =~ /^(\d+)(\.\.\.)?$/); + ($val,$elip) = ($val =~ /^(\d+)(\.\.\.?)?$/); $str = remove_html($str) || ''; my @words = split(/\s+/, $str); my $max = @words > $val ? $val : @words; @@ -632,4 +632,18 @@ sub tag_search_to { return $upper; } +sub mod_encode_json { + my ($str, $val, $ctx) = @_; + return '' unless defined $str; + $str =~ s!\\!\\\\!g; # \ + $str =~ s!\/!\\\/!g; # / + $str =~ s!"!\\"!g; # " + $str =~ s!\f!\\f!g; # \f + $str =~ s!\n!\\n!g; # \n + $str =~ s!\r!\\r!g; # \r + $str =~ s!\t!\\t!g; # \t + $str =~ s!\0!\\0!g; + $str; +} + 1;