First I thought html_break does

  Foo
  Bar

to

  Foo<br>
  Bar<br>

whish it doesn't. So this patch adds new html_linebreak filter to do
it. We always define this filter by ourselves, so I wish TT2 itself
has it.


--
Tatsuhiko Miyagawa <[EMAIL PROTECTED]>

Index: lib/Template/Filters.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Filters.pm,v
retrieving revision 2.61
diff -u -r2.61 Filters.pm
--- lib/Template/Filters.pm     2002/08/15 16:41:23     2.61
+++ lib/Template/Filters.pm     2002/08/16 07:46:10
@@ -50,6 +50,7 @@
     'html'       => \&html_filter,
     'html_para'  => \&html_paragraph,
     'html_break' => \&html_break,
+    'html_linebreak' => \&html_linebreak,
     'upper'      => sub { uc $_[0] },
     'lower'      => sub { lc $_[0] },
     'ucfirst'    => sub { ucfirst $_[0] },
@@ -328,7 +329,17 @@
     return $text;
 }
 
+#------------------------------------------------------------------------
+# html_linebreak()                            [% FILTER html_linebreak %]
+#
+# replaces any newlines with <br> HTML tags.
+#------------------------------------------------------------------------
 
+sub html_linebreak  {
+    my $text = shift;
+    $text =~ s/(\r?\n)/<br>$1/g;
+    return $text;
+}
 
 #========================================================================
 #                    -- DYNAMIC FILTER FACTORIES --
@@ -1052,7 +1063,7 @@
 these modules are installed on your system then the text will be
 encoded (via the escape_html() or encode_entities() subroutines
 respectively) to convert all extended characters into their
-appropriate HTML entities (e.g. converting '�' to '&eacute;').  If
+appropriate HTML entities (e.g. converting 'é' to '&eacute;').  If
 neither module is available on your system then an 'html_all' exception
 will be thrown reporting an appropriate message.   
 
@@ -1099,6 +1110,20 @@
     <br>
     Mary had a little lamb.
 
+=head2 html_linebreak
+
+This filter replaces any newlines with E<lt>brE<gt> HTML tags.
+
+    [% FILTER html_break %]
+    The cat sat on the mat.
+    Mary had a little lamb.
+    [% END %]
+
+output:
+
+    The cat sat on the mat.<br>
+    Mary had a little lamb.<br>
+
 =head2 uri
 
 This filter URI escapes the input text, converting any characters 
@@ -1379,4 +1404,4 @@
 
 =head1 SEE ALSO
 
-L<Template|Template>, L<Template::Context|Template::Context>, 
L<Template::Manual::Filters|Template::Manual::Filters>
\ No newline at end of file
+L<Template|Template>, L<Template::Context|Template::Context>, 
+L<Template::Manual::Filters|Template::Manual::Filters>
Index: t/filter.t
===================================================================
RCS file: /template-toolkit/Template2/t/filter.t,v
retrieving revision 2.15
diff -u -r2.15 filter.t
--- t/filter.t  2002/08/08 12:00:55     2.15
+++ t/filter.t  2002/08/16 07:46:13
@@ -419,6 +419,19 @@
 if I can't wait until then?  I'm hungry!
 
 -- test --
+[% global.blocktext FILTER html_linebreak %]
+
+-- expect --
+The cat sat on the mat<br>
+<br>
+Mary had a little Lamb<br>
+<br>
+<br>
+<br>
+You shall have a fishy on a little dishy, when the boat comes in.  What <br>
+if I can't wait until then?  I'm hungry!<br>
+
+-- test --
 [% global.blocktext FILTER truncate(10) %]
 
 -- expect --

_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://www.template-toolkit.org/mailman/listinfo/templates

Reply via email to