- def self.html_renderer
- @html_renderer ||= Redcarpet::Render::XHTML.new(:filter_html => true, :safe_links_only => true, :link_attributes => { :rel => "nofollow" })
+ def image
+ @image_element = first_image_element(document.root) unless defined? @image_element
+ @image_element.attr["src"] if @image_element
+ end
+
+ def image_alt
+ @image_element = first_image_element(document.root) unless defined? @image_element
+ @image_element.attr["alt"] if @image_element
+ end
+
+ private
+
+ 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