35 lines
887 B
Ruby
35 lines
887 B
Ruby
require "redcarpet"
|
|
|
|
module Merged
|
|
module SharedHelper
|
|
|
|
def renderer
|
|
options = {hard_wrap: true , autolink: true, no_intra_emphasis: true ,
|
|
safe_links_only: true, no_styles: true ,
|
|
link_attributes: { target: '_blank' }}
|
|
html = Redcarpet::Render::HTML.new(options)
|
|
Redcarpet::Markdown.new(html, options)
|
|
end
|
|
|
|
def prose_classes
|
|
classes = "prose md:prose-lg lg:prose-xl max-w-none "
|
|
classes += "prose-headings:text-inherit "
|
|
{ class: classes }
|
|
end
|
|
|
|
def markdown_image(section)
|
|
return "" unless section.text
|
|
down = self.renderer.render(section.text)
|
|
image = image_for(section)
|
|
down.gsub("IMAGE" , image).html_safe
|
|
end
|
|
|
|
def markdown(text)
|
|
text = text.text unless text.is_a?(String)
|
|
return "" if text.blank?
|
|
self.renderer.render(text).html_safe
|
|
end
|
|
|
|
end
|
|
end
|