cartodb-4.42/app/helpers/carto/html_safe.rb

30 lines
630 B
Ruby
Raw Normal View History

2024-04-06 13:25:13 +08:00
require_relative '../../models/markdown_render'
module Carto::HtmlSafe
def markdown_html_safe(text)
if text.present?
renderer = create_renderer(text)
markdown = Redcarpet::Markdown.new(renderer, extensions = {})
markdown.render text
end
end
def create_renderer(text)
if mailto?(text)
Redcarpet::Render::Safe.new
else
Redcarpet::Render::Safe.new(link_attributes: { target: '_blank' })
end
end
def markdown_html_clean(text)
if text.present?
markdown_html_safe(text).strip_tags
end
end
def mailto?(text)
text && text.include?('mailto:')
end
end