- def html_parser
- @@html_renderer ||= Redcarpet::Render::XHTML.new({
- :filter_html => true, :safe_links_only => true
- })
- @@html_parser ||= Redcarpet::Markdown.new(@@html_renderer, {
- :no_intra_emphasis => true, :autolink => true, :space_after_headers => true
- })
+ def document
+ @document ||= Kramdown::Document.new(self)
+ end
+
+ def first_image_element(element)
+ return element if image?(element) && element.attr["src"].present?
+
+ element.children.find do |child|
+ nested_image = first_image_element(child)
+ break nested_image if nested_image
+ end
+ end
+
+ def image?(element)
+ element.type == :img || (element.type == :html_element && element.value == "img")
+ end
+ end
+
+ class Text < Base
+ def to_html
+ linkify(simple_format(ERB::Util.html_escape(self)))
+ end
+
+ def to_text
+ to_s