* 1.5.0
+ * added a nl2br filter
* added a random function
* added a way to change the default format for the date filter
* fixed the lexer when an operator ending with a letter ends a line
convert_encoding
title
capitalize
+ nl2br
upper
lower
striptags
--- /dev/null
+``nl2br``
+=========
+
+The ``nl2br`` filter inserts HTML line breaks before all newlines in a string:
+
+.. code-block:: jinja
+
+ {{ "I like Twig.\nYou will like it too."|nl2br }}
+ {# outputs
+
+ I like Twig.<br />
+ You will like it too.
+
+ #}
+
+.. note::
+
+ The ``nl2br`` filter pre-escapes the input before applying the
+ transformation.
'upper' => new Twig_Filter_Function('strtoupper'),
'lower' => new Twig_Filter_Function('strtolower'),
'striptags' => new Twig_Filter_Function('strip_tags'),
+ 'nl2br' => new Twig_Filter_Function('nl2br', array('pre_escape' => 'html', 'is_safe' => array('html'))),
// array helpers
'join' => new Twig_Filter_Function('twig_join_filter'),
--- /dev/null
+--TEST--
+"nl2br" filter
+--TEMPLATE--
+{{ "I like Twig.\nYou will like it too.\n\nEverybody like it!"|nl2br }}
+{{ text|nl2br }}
+--DATA--
+return array('text' => "If you have some <strong>HTML</strong>\nit will be escaped.")
+--EXPECT--
+I like Twig.<br />
+You will like it too.<br />
+<br />
+Everybody like it!
+If you have some <strong>HTML</strong><br />
+it will be escaped.