diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-10-26 21:09:29 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-10-28 14:56:13 +0100 |
commit | 5541a0cfa0b4a69d8ed2c526dcf5f7d0eff0508b (patch) | |
tree | abea3589cadcfd89bacb9f2ec34f276957bbc995 | |
parent | 50379992dc95e242fd29f6e3473c70f2106749bc (diff) |
Add ability for admin users to italic updates.
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 18 | ||||
-rw-r--r-- | templates/web/base/report/update.html | 2 |
2 files changed, 19 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index ae06181c8..f0bcad0be 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -22,6 +22,7 @@ __PACKAGE__->config( FILTERS => { add_links => \&add_links, escape_js => \&escape_js, + markup => [ \&markup_factory, 1 ], }, COMPILE_EXT => '.ttc', STAT_TTL => FixMyStreet->config('STAGING_SITE') ? 1 : 86400, @@ -98,6 +99,23 @@ sub _space_slash { return $t; } +=head2 markup_factory + +This returns a function that will allow updates to have markdown-style italics. +Pass in the user that wrote the text, so we know whether it can be privileged. + +=cut + +sub markup_factory { + my ($c, $user) = @_; + return sub { + my $text = shift; + return $text unless $user && ($user->from_body || $user->is_superuser); + $text =~ s{\*(\S.*?\S)\*}{<i>$1</i>}; + $text; + } +} + =head2 escape_js Used to escape strings that are going to be put inside JavaScript. diff --git a/templates/web/base/report/update.html b/templates/web/base/report/update.html index 7c2c39eb2..d423a193d 100644 --- a/templates/web/base/report/update.html +++ b/templates/web/base/report/update.html @@ -31,7 +31,7 @@ [% INCLUDE 'report/photo.html' object=update %] <div class="item-list__update-text"> <div class="moderate-display"> - [% update.text | add_links | html_para %] + [% update.text | add_links | markup(update.user) | html_para %] </div> [% IF moderating %] <div class="moderate-edit"> |