feat(messages): render markdown in message body

uses redcarpet gem to render markdown to html. Also a html email template
is added.
This commit is contained in:
Philipp Rothmann 2023-01-30 13:14:37 +01:00
parent fb8ccfea4a
commit 1419827f66
7 changed files with 37 additions and 4 deletions

View file

@ -75,6 +75,7 @@ gem 'foodsoft_polls', path: 'plugins/polls'
# gem 'foodsoft_printer', path: 'plugins/printer' # gem 'foodsoft_printer', path: 'plugins/printer'
# gem 'foodsoft_uservoice', path: 'plugins/uservoice' # gem 'foodsoft_uservoice', path: 'plugins/uservoice'
group :development do group :development do
gem 'sqlite3', '~> 1.3.6' gem 'sqlite3', '~> 1.3.6'
gem 'mailcatcher' gem 'mailcatcher'
@ -126,3 +127,5 @@ group :test do
gem 'rswag-specs' gem 'rswag-specs'
gem 'hashie', '~> 3.4.6', require: false # https://github.com/westfieldlabs/apivore/issues/114 gem 'hashie', '~> 3.4.6', require: false # https://github.com/westfieldlabs/apivore/issues/114
end end
gem "redcarpet"

View file

@ -413,6 +413,7 @@ GEM
rb-fsevent (0.11.2) rb-fsevent (0.11.2)
rb-inotify (0.10.1) rb-inotify (0.10.1)
ffi (~> 1.0) ffi (~> 1.0)
redcarpet (3.6.0)
redis (5.0.5) redis (5.0.5)
redis-client (>= 0.9.0) redis-client (>= 0.9.0)
redis-client (0.11.2) redis-client (0.11.2)
@ -652,6 +653,7 @@ DEPENDENCIES
rails_tokeninput rails_tokeninput
ransack ransack
recurring_select! recurring_select!
redcarpet
resque resque
roo roo
roo-xls roo-xls
@ -686,4 +688,4 @@ DEPENDENCIES
whenever whenever
BUNDLED WITH BUNDLED WITH
2.4.3 2.4.5

View file

@ -263,4 +263,26 @@ module ApplicationHelper
stylesheet_link_tag foodcoop_css_path, media: 'all' stylesheet_link_tag foodcoop_css_path, media: 'all'
end end
end end
# renders html from markdown input
def markdown(text)
options = {
filter_html: true,
hard_wrap: true,
link_attributes: { rel: 'nofollow', target: "_blank" },
fenced_code_blocks: true
}
extensions = {
autolink: true,
superscript: true,
disable_indented_code_blocks: true,
tables: true,
strikethrough: true,
footnotes: true
}
renderer = ::Redcarpet::Render::HTML.new(options)
markdown = ::Redcarpet::Markdown.new(renderer, extensions)
markdown.render(text).html_safe
end
end end

View file

@ -33,7 +33,7 @@
- if @message.can_toggle_private?(current_user) - if @message.can_toggle_private?(current_user)
= link_to t('.change_visibility'), toggle_private_message_path(@message), method: :post, class: 'btn btn-mini' = link_to t('.change_visibility'), toggle_private_message_path(@message), method: :post, class: 'btn btn-mini'
%hr/ %hr/
%p= simple_format(h(@message.body)) = markdown(@message.body)
%hr/ %hr/
%p %p
= link_to t('.reply'), new_message_path(:message => {:reply_to => @message.id}), class: 'btn' = link_to t('.reply'), new_message_path(:message => {:reply_to => @message.id}), class: 'btn'

View file

@ -9,7 +9,7 @@
.panel-heading .panel-heading
%b= h(message.sender_name) %b= h(message.sender_name)
= format_time(message.created_at) = format_time(message.created_at)
.panel-body= simple_format(h(message.body)) .panel-body= markdown(message.body)
%p %p
= link_to t('.reply'), new_message_path(:message => {:reply_to => thread_message.id}), class: 'btn' = link_to t('.reply'), new_message_path(:message => {:reply_to => thread_message.id}), class: 'btn'

View file

@ -0,0 +1,6 @@
= markdown(@message.body)
%hr/
%pre
- if @message.group
= raw t '.footer_group', group: @message.group.name
= raw t '.footer', reply_url: new_message_url('message[reply_to]' => @message.id), msg_url: message_url(@message), profile_url: my_profile_url