2023-02-22 05:00:42 +01:00
|
|
|
module Redcarpet
|
|
|
|
class BareRenderer < Redcarpet::Render::HTML
|
|
|
|
include ActionView::Helpers::TagHelper
|
2023-03-22 12:48:53 +01:00
|
|
|
include ApplicationHelper
|
2023-02-22 05:00:42 +01:00
|
|
|
|
|
|
|
# won't use rubocop tag method because it is missing output buffer
|
|
|
|
def list(content, list_type)
|
|
|
|
tag = list_type == :ordered ? :ol : :ul
|
|
|
|
content_tag(tag, content, { class: @options[:class_names_map].fetch(:list) {} }, false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def list_item(content, list_type)
|
2023-07-26 18:55:02 +02:00
|
|
|
item_number = content.match(/\[value:(\d+)\]/)
|
|
|
|
text = content.strip
|
|
|
|
.gsub(/<\/?p>/, '')
|
|
|
|
.gsub(/\[value:\d+\]/, '')
|
|
|
|
.gsub(/\n/, '<br>')
|
|
|
|
attributes = item_number.present? ? { value: item_number[1] } : {}
|
|
|
|
|
|
|
|
content_tag(:li, text, attributes, false)
|
2023-02-22 05:00:42 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def paragraph(text)
|
|
|
|
content_tag(:p, text, { class: @options[:class_names_map].fetch(:paragraph) {} }, false)
|
|
|
|
end
|
2023-03-22 12:48:53 +01:00
|
|
|
|
|
|
|
def link(href, title, content)
|
|
|
|
content_tag(:a, content, { href:, title: new_tab_suffix(title), **external_link_attributes }, false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def autolink(link, link_type)
|
2023-03-29 12:17:08 +02:00
|
|
|
case link_type
|
|
|
|
when :url
|
|
|
|
link(link, nil, link)
|
|
|
|
when :email
|
2024-03-12 16:49:49 +01:00
|
|
|
# NOTE: As of Redcarpet 3.6.0, autolinking email containing underscore is broken https://github.com/vmg/redcarpet/issues/402
|
2023-03-29 12:17:08 +02:00
|
|
|
content_tag(:a, link, { href: "mailto:#{link}" })
|
|
|
|
else
|
|
|
|
link
|
|
|
|
end
|
2023-03-22 12:48:53 +01:00
|
|
|
end
|
2023-02-22 05:00:42 +01:00
|
|
|
end
|
|
|
|
end
|