Sha256: e4cd1ec58a13f353487f287d6aeccec11ff8f50c3c32ec29b9ec16ab8ef1ba1f

Contents?: true

Size: 878 Bytes

Versions: 13

Compression:

Stored size: 878 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,
      lax_spacing: true
    }

    def self.render(text)
      text&.gsub!(/<!-- (BEGIN|END) (.*) -->/, "")
      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::Code::Component.new(**{
          source: code,
          language: language.to_s.chomp("-numbered"),
          line_numbers: line_numbers
        }), layout: nil)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
lookbook-1.0.8 lib/lookbook/markdown.rb
lookbook-1.0.7 lib/lookbook/markdown.rb
lookbook-1.0.6 lib/lookbook/markdown.rb
lookbook-1.0.5 lib/lookbook/markdown.rb
lookbook-1.0.4 lib/lookbook/markdown.rb
lookbook-1.0.3 lib/lookbook/markdown.rb
lookbook-1.0.2 lib/lookbook/markdown.rb
lookbook-1.0.1 lib/lookbook/markdown.rb
lookbook-1.0.0 lib/lookbook/markdown.rb
lookbook-1.0.0.rc.3 lib/lookbook/markdown.rb
lookbook-1.0.0.rc.2 lib/lookbook/markdown.rb
lookbook-1.0.0.rc.1 lib/lookbook/markdown.rb
lookbook-1.0.0.beta.8 lib/lookbook/markdown.rb