Sha256: eeba6a6d06744cab545ecfa4bca381eb06a6da03537b26cf566d911d22781253

Contents?: true

Size: 655 Bytes

Versions: 2

Compression:

Stored size: 655 Bytes

Contents

require "redcarpet"

module Lookbook
  class Markdown
    def self.render(text)
      Utils.strip_action_view_annotations!(text)
      markdown = Redcarpet::Markdown.new(Renderer, Lookbook.config.markdown_options.to_h)
      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::Code::Component.new(**{
          source: code,
          language: language.to_s.chomp("-numbered"),
          line_numbers: line_numbers
        }), layout: nil)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lookbook-1.2.1 lib/lookbook/markdown.rb
lookbook-1.2.0 lib/lookbook/markdown.rb