Sha256: 287e71aef78fabd0e06eb371de1194841eab0822b480c27aa24962bca045b31a

Contents?: true

Size: 964 Bytes

Versions: 2

Compression:

Stored size: 964 Bytes

Contents

# Encoding: utf-8
require "pygments"
require "redcarpet"


module SlideEmUp
  class Markdown < Redcarpet::Render::HTML
    PARSER_OPTIONS = {
      :no_intra_emphasis  => true,
      :tables             => true,
      :fenced_code_blocks => true,
      :autolink           => true,
      :strikethrough      => true,
      :superscript        => true
    }

    def self.render(text)
      text ||= ""
      markdown = Redcarpet::Markdown.new(self, PARSER_OPTIONS)
      markdown.render(text)
    end

    def block_code(code, lang)
      colorized = Pygments.highlight(code, :lexer => lang || "text", :options => {:nowrap => true})
      "<pre><code class=\"#{lang}\">#{colorized}</code></pre>"
    end

    def strikethrough(text)
      "<s>#{text}</s>"
    end

    def normal_text(text)
      text.gsub!('« ', '«&nbsp;')
      text.gsub!(/ ([:;»!?])/, '&nbsp;\1')
      text.gsub!(' -- ', '—')
      text.gsub!('...', '…')
      text
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
slide-em-up-0.3.5 lib/slide-em-up/markdown.rb
slide-em-up-0.3.4 lib/slide-em-up/markdown.rb