Skip to content

Commit

Permalink
Remove markdown tags in notifications' excerpts
Browse files Browse the repository at this point in the history
Use a render that strips the markdown tags. This way we show a more
understandable excerpt in the list of notifications.
  • Loading branch information
eduardoj committed Sep 25, 2020
1 parent 66b678d commit ba0cead
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/api/app/presenters/notification_presenter.rb
@@ -1,3 +1,5 @@
require 'redcarpet/render_strip'

class NotificationPresenter < SimpleDelegator
TRUNCATION_LENGTH = 100
TRUNCATION_ELLIPSIS_LENGTH = 3 # `...` is the default ellipsis for String#truncate
Expand Down Expand Up @@ -42,7 +44,7 @@ def excerpt
when 'Review'
@model.notifiable.reason
when 'Comment'
@model.notifiable.body
render_without_markdown(@model.notifiable.body)
else
''
end
Expand Down Expand Up @@ -70,4 +72,12 @@ def avatar_objects
@model.notifiable.reviews.in_state_new.map(&:reviewed_by) + User.where(login: @model.notifiable.creator)
end
end

private

def render_without_markdown(content)
# Initializes a Markdown parser, if needed
@remove_markdown_parser ||= Redcarpet::Markdown.new(Redcarpet::Render::StripDown)
ActionController::Base.helpers.sanitize(@remove_markdown_parser.render(content.to_s))
end
end

0 comments on commit ba0cead

Please sign in to comment.