aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/View/Web.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-08-12 16:25:15 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-08-12 17:40:44 +0100
commitda4135d0b163bdf3033ebb8a49e86ceaaaec00b6 (patch)
tree8dd7a11562ea0e160d93866619ba32002afe2a36 /perllib/FixMyStreet/App/View/Web.pm
parent12bddad6bd46d402e55a3c33475cf24a36e84657 (diff)
Convert single newlines in text to <br>s.
Fixes #306.
Diffstat (limited to 'perllib/FixMyStreet/App/View/Web.pm')
-rw-r--r--perllib/FixMyStreet/App/View/Web.pm16
1 files changed, 16 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm
index f3377f7fb..b750bc4e5 100644
--- a/perllib/FixMyStreet/App/View/Web.pm
+++ b/perllib/FixMyStreet/App/View/Web.pm
@@ -23,6 +23,7 @@ __PACKAGE__->config(
add_links => \&add_links,
escape_js => \&escape_js,
html => \&html_filter,
+ html_para => \&html_paragraph,
},
COMPILE_EXT => '.ttc',
STAT_TTL => FixMyStreet->config('STAGING_SITE') ? 1 : 86400,
@@ -167,6 +168,21 @@ sub html_filter {
return $text;
}
+=head2 html_paragraph
+
+Same as Template Toolkit's html_paragraph, but converts single newlines
+into <br>s too.
+
+=cut
+
+sub html_paragraph {
+ my $text = shift;
+ my @paras = split(/(?:\r?\n){2,}/, $text);
+ s/\r?\n/<br>\n/ for @paras;
+ $text = "<p>\n" . join("\n</p>\n\n<p>\n", @paras) . "</p>\n";
+ return $text;
+}
+
my %version_hash;
sub version {
my ( $self, $c, $file ) = @_;