Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Applied patch from Johannes Plunien to add an option to disable any H…

…TML entity encoding (this is off by default). Version bump to 2.10.
  • Loading branch information...
commit 919a93a7295a2a99710911a18144f255ec614d14 1 parent 82c197c
@bradchoate authored
View
7 Changes
@@ -4,18 +4,21 @@
- Fixed an incorrectly defined lexical variable.
+- Applied a patch submitted by Ryan McGuigan to prevent clobbering $_.
+- Applied a patch from Johannes Plunien to add the 'disable_encode_entities'
+option.
2.03 - No changes. Just needed to bump version # for CPAN.
-2.02 - Removed Encode package usage altogether until compatability
+2.02 - Removed Encode package usage altogether until compatibility
issues can be ironed out. Modified newline translation to be more
cross-platform friendly.
2.01 - Patches to fix issues with older versions of Perl.
-2.0 - Many, many fixes and improvments.
+2.0 - Many, many fixes and improvements.
- Added 'dl' paragraph block which allows for definition lists.
View
1  MANIFEST
@@ -9,4 +9,5 @@ t/02paragraph.t
t/03url.t
t/04list.t
t/05combined.t
+t/06disable_encode_entities.t
t/pod.t
View
17 lib/Text/Textile.pm
@@ -7,7 +7,7 @@ use warnings;
use base 'Exporter';
our @EXPORT_OK = qw(textile);
-our $VERSION = 2.03;
+our $VERSION = 2.10;
our $debug = 0;
sub new {
@@ -19,7 +19,7 @@ sub new {
for ( qw( char_encoding do_quotes smarty_mode ) ) {
$options{$_} = 1 unless exists $options{$_};
}
- for ( qw( trim_spaces preserve_spaces head_offset ) ) {
+ for ( qw( trim_spaces preserve_spaces head_offset disable_encode_entities ) ) {
$options{$_} = 0 unless exists $options{$_};
}
@@ -178,6 +178,12 @@ sub char_encoding {
return $self->{char_encoding};
}
+sub disable_encode_entities {
+ my $self = shift;
+ $self->{disable_encode_entities} = shift if @_;
+ $self->{disable_encode_entities};
+}
+
sub handle_quotes {
my $self = shift;
$self->{do_quotes} = shift if @_;
@@ -1921,6 +1927,7 @@ sub apply_filters {
my $self = shift;
my($html, $can_double_encode) = @_;
return '' unless defined $html;
+ return $html if $self->{disable_encode_entities};
if ($Have_Entities && $self->{char_encoding}) {
$html = HTML::Entities::encode_entities($html);
} else {
@@ -2473,6 +2480,12 @@ encoding is enabled, the HTML::Entities package is used to
encode special characters. If character encoding is disabled,
only C<< < >>, C<< > >>, C<"> and C<&> are encoded to HTML entities.
+=head2 disable_encode_entities( $boolean )
+
+Gets or sets the disable encode entities logical flag. If this
+value is set to true no entities are encoded at all. This
+also supersedes the "char_encoding" flag.
+
=head2 handle_quotes( [$handle] )
Gets or sets the "smart quoting" control flag. Returns the
View
90 t/06disable_encode_entities.t
@@ -0,0 +1,90 @@
+use warnings;
+use strict;
+use Test::More tests => 2;
+use Text::Textile;
+
+{
+ my $tt = Text::Textile->new( disable_encode_entities => 1 );
+
+ my $source = <<SOURCE;
+start paragraph
+
+another paragraph
+
+* list of things with "urls":http://www.jerakeen.org in
+* more things in the list
+
+a http://bare.url.here. and an email\@address.com
+
+>>> No encode_entities here
+<<< and there
+&&& and here too
+
+SOURCE
+
+ my $dest = $tt->process($source);
+ $dest =~ s/(^\s+|\s+$)//g;
+
+ my $expected = <<EXPECTED;
+<p>start paragraph</p>
+
+<p>another paragraph</p>
+
+<ul>
+<li>list of things with <a href="http://www.jerakeen.org">urls</a> in</li>
+<li>more things in the list</li>
+</ul>
+
+<p>a http://bare.url.here. and an email\@address.com</p>
+
+<p>>>> No encode_entities here<br />
+<<< and there<br />
+&&& and here too</p>
+EXPECTED
+ $expected =~ s/(^\s+|\s+$)//g;
+
+ is( $dest, $expected );
+}
+
+{
+ my $tt = Text::Textile->new( disable_encode_entities => 0 );
+
+ my $source = <<SOURCE;
+start paragraph
+
+another paragraph
+
+* list of things with "urls":http://www.jerakeen.org in
+* more things in the list
+
+a http://bare.url.here. and an email\@address.com
+
+>>> encode_entities here
+<<< and there
+&&& and here too
+
+SOURCE
+
+ my $dest = $tt->process($source);
+ $dest =~ s/(^\s+|\s+$)//g;
+
+ my $expected = <<EXPECTED;
+<p>start paragraph</p>
+
+<p>another paragraph</p>
+
+<ul>
+<li>list of things with <a href="http://www.jerakeen.org">urls</a> in</li>
+<li>more things in the list</li>
+</ul>
+
+<p>a http://bare.url.here. and an email\@address.com</p>
+
+<p>&gt;&gt;&gt; encode_entities here<br />
+&lt;&lt;&lt; and there<br />
+&amp;&amp;&amp; and here too</p>
+EXPECTED
+ $expected =~ s/(^\s+|\s+$)//g;
+
+ is( $dest, $expected );
+}
Please sign in to comment.
Something went wrong with that request. Please try again.