module Markdown::Engine

Public Instance Methods

bluecloth_to_html( content, options={} ) click to toggle source
# File lib/markdown/engines/bluecloth.rb, line 10
def bluecloth_to_html( content, options={} )
  puts "  Converting Markdown-text (#{content.length} bytes) to HTML using library bluecloth..."

  BlueCloth.new( content ).to_html
end
bluecloth_version() click to toggle source
# File lib/markdown/engines/bluecloth.rb, line 6
def bluecloth_version
  BlueCloth::VERSION
end
kramdown_to_html( content, options={} ) click to toggle source
# File lib/markdown/engines/kramdown.rb, line 10
    def kramdown_to_html( content, options={} )

      h = {}
      
      # todo: find an easier (more generic?) way to setup hash - possible?
      h[ :auto_ids    ]   = options.fetch( 'auto_ids', nil )     if options.fetch( 'auto_ids',      nil )
      h[ :footnote_nr ]   = options.fetch( 'footnote_nr',nil )   if options.fetch( 'footnote_nr',   nil )
      h[ :entity_output ] = options.fetch( 'entity_output',nil ) if options.fetch( 'entity_output', nil )
      h[ :toc_levels ]    = options.fetch( 'toc_levels',nil )    if options.fetch( 'toc_levels',    nil )
      h[ :smart_quotes ]  = options.fetch( 'smart_quotes',nil )  if options.fetch( 'smart_quotes',  nil )
      
      show_banner =  options.fetch( 'banner', true)

      # puts "  Converting Markdown-text (#{content.length} bytes) to HTML using library kramdown (#{Kramdown::VERSION})"
      # puts "  using options: #{h.to_json}"

      ## allow fenced blocks a la github flavored markup
      # -- thanks zenweb for inspiration:
      #  https://github.com/seattlerb/zenweb/blob/master/lib/zenweb/plugins/markdown.rb

      content = content.
        gsub(/^``` *(\w+)/) { "{:lang=\"#$1\"}\n~~~" }.
        gsub(/^```/, '~~~')
      
      content = Kramdown::Document.new( content, h ).to_html
      
      if show_banner

       # todo: check content size and newlines
       #  check banner option?
       #  only add banner if some newlines and size > treshold?
      
      banner_begin =<<EOS
<!-- === begin markdown block ===

      generated by #{Markdown.banner}
                on #{Time.now} with Markdown engine kramdown (#{Kramdown::VERSION})
                  using options #{h.to_json}
  -->
EOS

       banner_end =<<EOS
<!-- === end markdown block === -->
EOS
        content = banner_begin + content + banner_end
      end # if show_banner

      content

    end
kramdown_version() click to toggle source
# File lib/markdown/engines/kramdown.rb, line 6
def kramdown_version
  Kramdown::VERSION
end
maruku_to_html( content, options={} ) click to toggle source
# File lib/markdown/engines/maruku.rb, line 10
def maruku_to_html( content, options={} )
  puts "  Converting Markdown-text (#{content.length} bytes) to HTML using library maruku..."
        
  Maruku.new( content, {:on_error => :raise} ).to_html
end
maruku_version() click to toggle source
# File lib/markdown/engines/maruku.rb, line 6
def maruku_version
  Maruku::VERSION
end
pandoc_ruby_to_html( content, options={} ) click to toggle source
# File lib/markdown/engines/pandoc_ruby.rb, line 6
def pandoc_ruby_to_html( content, options={} )
  puts "  Converting Markdown-text (#{content.length} bytes) to HTML using library pandoc_ruby..."

  content = PandocRuby.new( content, :from => :markdown, :to => :html ).convert
end
pandoc_ruby_to_html_incremental( content, options={} ) click to toggle source
# File lib/markdown/engines/pandoc_ruby.rb, line 12
def pandoc_ruby_to_html_incremental( content, options={} )
  content = PandocRuby.new( content, :from => :markdown, :to => :html ).convert
  content = content.gsub(/<(ul|ol)/) do |match|
    "#{Regexp.last_match(0)} class='step'"
  end
  content
end
pandoc_ruby_to_s5( content, options={} ) click to toggle source

sample how to use your own converter configure in markdown.yml pandoc-ruby:

converter: pandoc-ruby-to-s5
# File lib/markdown/engines/pandoc_ruby.rb, line 25
def pandoc_ruby_to_s5( content, options={} )
  content = PandocRuby.new( content, {:from => :markdown, :to => :s5}, :smart ).convert
  content = content.gsub(/class="incremental"/,'class="step"')
  content = content.to_a[13..-1].join # remove the layout div
end
pandoc_ruby_to_s5_incremental( content, options={} ) click to toggle source
# File lib/markdown/engines/pandoc_ruby.rb, line 31
def pandoc_ruby_to_s5_incremental( content, options={} )
  content = PandocRuby.new( content, {:from => :markdown, :to => :s5 }, :incremental, :smart ).convert
  content = content.gsub(/class="incremental"/,'class="step"')
  content = content.to_a[13..-1].join # remove the layout div
end
rdiscount_to_html( content, options={} ) click to toggle source
# File lib/markdown/engines/rdiscount.rb, line 10
def rdiscount_to_html( content, options={} )
  puts "  Converting Markdown-text (#{content.length} bytes) to HTML using library rdiscount..."      
  
  RDiscount.new( content ).to_html
end
rdiscount_version() click to toggle source
# File lib/markdown/engines/rdiscount.rb, line 6
def rdiscount_version
  RDiscount::VERSION
end
redcarpet_to_html( content, options={} ) click to toggle source
# File lib/markdown/engines/redcarpet.rb, line 10
    def redcarpet_to_html( content, options={} )
      
      ## NB: uses redcarpet2
      #
      # see https://github.com/tanoku/redcarpet
      
      extensions_ary = options.fetch( 'extensions', [] )
      show_banner = options.fetch( 'banner', true )

      extensions_hash = {}
      extensions_ary.each do |e|
        extensions_hash[ e.to_sym ] = true
      end

      puts "  Converting Markdown-text (#{content.length} bytes) to HTML using library redcarpet (#{Redcarpet::VERSION}) w/ HTML render"
      puts "  using extensions: #{extensions_ary.to_json}"
      
      redcarpet = Redcarpet::Markdown.new( Redcarpet::Render::HTML, extensions_hash )
      content = redcarpet.render( content )

      if show_banner
        # todo: check content size and newlines
        #  check banner option?
        #  only add banner if some newlines and size > treshold?
      
      banner_begin =<<EOS
<!-- === begin markdown block ===

      generated by #{Markdown.banner}
                on #{Time.now} with Markdown engine redcarpet (#{Redcarpet::VERSION}) w/ HTML render
                  using extensions: #{extensions_ary.to_json}
  -->
EOS

      banner_end =<<EOS
<!-- === end markdown block === -->
EOS

        content = banner_begin + content + banner_end
      end # if show_banner

      content
      
    end
redcarpet_version() click to toggle source
# File lib/markdown/engines/redcarpet.rb, line 6
def redcarpet_version
  Redcarpet::VERSION
end
rpeg_markdown_to_html( content, options={} ) click to toggle source
# File lib/markdown/engines/rpeg_markdown.rb, line 6
def rpeg_markdown_to_html( content, options={} )
  puts "  Converting Markdown-text (#{content.length} bytes) to HTML using library rpeg_markdown..."

  PEGMarkdown.new( content ).to_html
end