Sha256: 3b6280c5b65bd2fdf39b3b6b9ea9f2803fde20cb594a4aa69d93faf381c5ba6c

Contents?: true

Size: 811 Bytes

Versions: 18

Compression:

Stored size: 811 Bytes

Contents

require "redcarpet"

module Lookbook
  class Markdown
    DEFAULT_OPTIONS = {
      tables: true,
      fenced_code_blocks: true,
      disable_indented_code_blocks: true,
      strikethrough: true,
      highlight: true,
      with_toc_data: true
    }

    def self.render(text)
      markdown = Redcarpet::Markdown.new(Renderer, Lookbook.config.markdown_options)
      markdown.render(text).html_safe
    end

    class Renderer < Redcarpet::Render::HTML
      def block_code(code, language = "ruby")
        line_numbers = language.to_s.end_with? "-numbered"
        ApplicationController.render "lookbook/components/_code", locals: {
          code: code,
          language: language.to_s.chomp("-numbered"),
          line_numbers: line_numbers
        },
        layout: nil
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
lookbook-0.9.1 lib/lookbook/markdown.rb
lookbook-0.9.0 lib/lookbook/markdown.rb
lookbook-0.8.3 lib/lookbook/markdown.rb
lookbook-0.8.2 lib/lookbook/markdown.rb
lookbook-0.8.1 lib/lookbook/markdown.rb
lookbook-0.8.0 lib/lookbook/markdown.rb
lookbook-0.8.0.beta.0 lib/lookbook/markdown.rb
lookbook-0.7.4 lib/lookbook/markdown.rb
lookbook-0.7.3 lib/lookbook/markdown.rb
lookbook-0.7.2 lib/lookbook/markdown.rb
lookbook-0.7.2.beta.5 lib/lookbook/markdown.rb
lookbook-0.7.2.beta.4 lib/lookbook/markdown.rb
lookbook-0.7.2.beta.3 lib/lookbook/markdown.rb
lookbook-0.7.2.beta.2 lib/lookbook/markdown.rb
lookbook-0.7.2.beta.1 lib/lookbook/markdown.rb
lookbook-0.7.2.beta.0 lib/lookbook/markdown.rb
lookbook-0.7.1 lib/lookbook/markdown.rb
lookbook-0.7.0 lib/lookbook/markdown.rb