Sha256: 58e27450ca9ee01ef02e5ae6310504ff0fdd6e626b018789e2e9b0ba67eb7e98

Contents?: true

Size: 1.09 KB

Versions: 9

Compression:

Stored size: 1.09 KB

Contents

module Kitabu
  class Markdown
    # Supported Markdown libraries
    #
    MARKDOWN_LIBRARIES = %w[Maruku BlueCloth PEGMarkdown Redcarpet RDiscount]

    # Retrieve preferred Markdown processor.
    # You'll need one of the following libraries:
    #
    # # RDiscount: https://rubygems.org/gems/rdiscount
    # # Maruku: https://rubygems.org/gems/maruku
    # # PEGMarkdown: https://rubygems.org/gems/rpeg-markdown
    # # BlueCloth: https://rubygems.org/gems/bluecloth
    # # Redcarpet: https://rubygems.org/gems/redcarpet
    #
    # Note: RDiscount will always be installed as Kitabu's dependency but only used when no
    # alternative library is available.
    #
    def self.engine
      @engine ||= Object.const_get(MARKDOWN_LIBRARIES.find {|lib| Object.const_defined?(lib)})
    end

    # Convert Markdown to HTML.
    def self.to_html(content)
      case engine.name
      when "Redcarpet"
        render = Redcarpet::Render::HTML.new(:hard_wrap => true, :xhtml => true)
        Redcarpet::Markdown.new(render).render(content)
      else
        engine.new(content).to_html
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
kitabu-1.0.6 lib/kitabu/adapters/markdown.rb
kitabu-1.0.5 lib/kitabu/adapters/markdown.rb
kitabu-1.0.4 lib/kitabu/adapters/markdown.rb
kitabu-1.0.3 lib/kitabu/adapters/markdown.rb
kitabu-1.0.2 lib/kitabu/adapters/markdown.rb
kitabu-1.0.1 lib/kitabu/adapters/markdown.rb
kitabu-1.0.0 lib/kitabu/adapters/markdown.rb
kitabu-1.0.0.rc4 lib/kitabu/adapters/markdown.rb
kitabu-1.0.0.rc3 lib/kitabu/adapters/markdown.rb