diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-08-12 16:25:15 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-08-12 17:40:44 +0100 |
commit | da4135d0b163bdf3033ebb8a49e86ceaaaec00b6 (patch) | |
tree | 8dd7a11562ea0e160d93866619ba32002afe2a36 | |
parent | 12bddad6bd46d402e55a3c33475cf24a36e84657 (diff) |
Convert single newlines in text to <br>s.
Fixes #306.
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 16 |
2 files changed, 17 insertions, 0 deletions
@@ -56,6 +56,7 @@ web-based cross-browser testing tools for this project. - Rename "Your reports" in main navigation to "Your account". - Centre map on pin location when creating a report. - Zoom into map after second click on marker. + - Maintain single newlines in text output. #306 - Admin improvements: - Greatly improve report edit page, including map. #1347 - Show any waiting reports on admin index page. #1382 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 ) = @_; |