Sha256: 99af2705aededbc3fce545af6526b3d54ad4691dfdae06d89c1e450239ab38a4

Contents?: true

Size: 607 Bytes

Versions: 2

Compression:

Stored size: 607 Bytes

Contents

module Schnitzelpress
  class MarkdownRenderer < Redcarpet::Render::HTML
    include Redcarpet::Render::SmartyPants

    def block_code(code, language)
      CodeRay.highlight(code, language)
    end

    def image(link, title, alt_text)
      oembed = OEmbed::Providers.get(link)
      %q(<div class="embedded %s %s">%s</div>) % [oembed.type, oembed.provider_name.parameterize, oembed.html]
    rescue OEmbed::NotFound
      %q(<img src="%s" title="%s" alt="%s"/>) % [link, escape_html(title), escape_html(alt_text)]
    end

    def escape_html(html)
      Rack::Utils.escape_html(html)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
schnitzelpress-0.2.1 lib/schnitzelpress/markdown_renderer.rb
schnitzelpress-0.2.0 lib/schnitzelpress/markdown_renderer.rb