Compare commits

..

1 commit

Author SHA1 Message Date
Philipp Rothmann
d2d7d0c4f9 feat(messages): render markdown in message body
uses redcarpet gem to render markdown to html. Also a html email template
is added.
2023-01-30 13:23:29 +01:00
7 changed files with 10 additions and 27 deletions

View file

@ -128,4 +128,4 @@ group :test do
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" gem "redcarpet", "~> 3.6"

View file

@ -653,7 +653,7 @@ DEPENDENCIES
rails_tokeninput rails_tokeninput
ransack ransack
recurring_select! recurring_select!
redcarpet redcarpet (~> 3.6)
resque resque
roo roo
roo-xls roo-xls

View file

@ -263,26 +263,4 @@ 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

@ -132,6 +132,11 @@ class Message < ApplicationRecord
user.role_admin? user.role_admin?
end end
def render_markdown
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true, strikethrough: true, footnotes: true)
return markdown.render(body)
end
private private
def create_salt def create_salt

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/
= markdown(@message.body) = raw @message.render_markdown
%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= markdown(message.body) .panel-body= simple_format(h(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

@ -1,4 +1,4 @@
= markdown(@message.body) = raw @message.render_markdown
%hr/ %hr/
%pre %pre
- if @message.group - if @message.group