Sha256: 671b8e0bd4c6ac6878c2d78b7ba4b71ee7366285c4faa8f47bee1e0a4b5a2b9e

Contents?: true

Size: 910 Bytes

Versions: 7

Compression:

Stored size: 910 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)
      text&.gsub!("<!-- BEGIN inline template -->", "")&.gsub!("<!-- END inline template -->", "")
      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

7 entries across 7 versions & 1 rubygems

Version Path
lookbook-0.9.8 lib/lookbook/markdown.rb
lookbook-0.9.7 lib/lookbook/markdown.rb
lookbook-0.9.6 lib/lookbook/markdown.rb
lookbook-0.9.5 lib/lookbook/markdown.rb
lookbook-0.9.4 lib/lookbook/markdown.rb
lookbook-0.9.3 lib/lookbook/markdown.rb
lookbook-0.9.2 lib/lookbook/markdown.rb