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 /perllib/FixMyStreet | |
parent | 50379992dc95e242fd29f6e3473c70f2106749bc (diff) |
Add ability for admin users to italic updates.
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 18 |
1 files changed, 18 insertions, 0 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. |