demarches-normaliennes/app/lib/redcarpet/bare_renderer.rb
Colin Darie 95315788f6
fix: handle all autolinks manually
On ne peut pas appeler super() qui est en méthode en C, pas en ruby.
Donc on doit gérer manuellement les cas possibles.
2023-03-29 13:57:41 +02:00

38 lines
1.1 KiB
Ruby

module Redcarpet
class BareRenderer < Redcarpet::Render::HTML
include ActionView::Helpers::TagHelper
include ApplicationHelper
# won't use rubocop tag method because it is missing output buffer
# rubocop:disable Rails/ContentTag
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)
content_tag(:li, content.strip.gsub(/<\/?p>/, ''), {}, false)
end
def paragraph(text)
content_tag(:p, text, { class: @options[:class_names_map].fetch(:paragraph) {} }, false)
end
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)
case link_type
when :url
link(link, nil, link)
when :email
content_tag(:a, link, { href: "mailto:#{link}" })
else
link
end
end
# rubocop:enable Rails/ContentTag
end
end