Module: Markdown::Engine

Included in:
Wrapper
Defined in:
lib/markdown/engines/maruku.rb,
lib/markdown/engines/kramdown.rb,
lib/markdown/engines/bluecloth.rb,
lib/markdown/engines/rdiscount.rb,
lib/markdown/engines/redcarpet.rb,
lib/markdown/engines/pandoc_ruby.rb,
lib/markdown/engines/rpeg_markdown.rb

Instance Method Summary collapse

Instance Method Details

#bluecloth_to_html(content, options = {}) ⇒ Object



4
5
6
7
8
# File 'lib/markdown/engines/bluecloth.rb', line 4

def bluecloth_to_html( content, options={} )
  puts "  Converting Markdown-text (#{@content.length} bytes) to HTML using library bluecloth..."

  BlueCloth.new( content ).to_html
end

#kramdown_to_html(content, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/markdown/engines/kramdown.rb', line 4

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 )

  puts "  Converting Markdown-text (#{@content.length} bytes) to HTML using library kramdown (#{Kramdown::VERSION})"
  puts "  using options:"
  pp h    # todo: use inspect? or 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
  
  # 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 { !to be done! }
  -->
EOS

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

  content = banner_begin + content + banner_end
  
end

#maruku_to_html(content, options = {}) ⇒ Object



4
5
6
7
8
# File 'lib/markdown/engines/maruku.rb', line 4

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

#pandoc_ruby_to_html(content, options = {}) ⇒ Object



4
5
6
7
8
# File 'lib/markdown/engines/pandoc_ruby.rb', line 4

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 = {}) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/markdown/engines/pandoc_ruby.rb', line 10

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 = {}) ⇒ Object

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

converter: pandoc-ruby-to-s5


23
24
25
26
27
# File 'lib/markdown/engines/pandoc_ruby.rb', line 23

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 = {}) ⇒ Object



29
30
31
32
33
# File 'lib/markdown/engines/pandoc_ruby.rb', line 29

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 = {}) ⇒ Object



4
5
6
7
8
# File 'lib/markdown/engines/rdiscount.rb', line 4

def rdiscount_to_html( content, options={} )
  puts "  Converting Markdown-text (#{@content.length} bytes) to HTML using library rdiscount..."      
  
  RDiscount.new( content ).to_html
end

#redcarpet_to_html(content, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/markdown/engines/redcarpet.rb', line 4

def redcarpet_to_html( content, options={} )
  
  ## NB: uses redcarpet2
  #
  # see https://github.com/tanoku/redcarpet
  
  extensions_ary = options.fetch( 'extensions', [] )
  
  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.join(', ')}]"
  
  redcarpet = Redcarpet::Markdown.new( Redcarpet::Render::HTML, extensions_hash )
  content = redcarpet.render( content )

  # 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.join(', ')}]
  -->
EOS

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

  content = banner_begin + content + banner_end
  
  
end

#rpeg_markdown_to_html(content, options = {}) ⇒ Object



4
5
6
7
8
# File 'lib/markdown/engines/rpeg_markdown.rb', line 4

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