Sha256: ddbef9f8f94833946c6438a7630d9735b77779ea1b8e2572abf006018e789ab3

Contents?: true

Size: 738 Bytes

Versions: 6

Compression:

Stored size: 738 Bytes

Contents

require "redcarpet"

module Lookbook
  class MarkdownRenderer < Service
    attr_reader :text, :opts

    def initialize(text, opts = {})
      @text = text
      @opts = opts.to_h
    end

    def call
      clean_text = ActionViewAnnotationsStripper.call(text)
      md = Redcarpet::Markdown.new(LookbookMarkdownRenderer, opts)
      md.render(clean_text).html_safe
    end

    class LookbookMarkdownRenderer < 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

6 entries across 6 versions & 1 rubygems

Version Path
lookbook-1.5.5 lib/lookbook/services/markdown_renderer.rb
lookbook-1.5.4 lib/lookbook/services/markdown_renderer.rb
lookbook-1.5.3 lib/lookbook/services/markdown_renderer.rb
lookbook-1.5.2 lib/lookbook/services/markdown_renderer.rb
lookbook-1.5.1 lib/lookbook/services/markdown_renderer.rb
lookbook-1.5.0 lib/lookbook/services/markdown_renderer.rb