Module: Markdown::Engine
- 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
- #bluecloth_to_html(content, options = {}) ⇒ Object
- #bluecloth_version ⇒ Object
- #kramdown_to_html(content, options = {}) ⇒ Object
- #kramdown_version ⇒ Object
- #maruku_to_html(content, options = {}) ⇒ Object
- #maruku_version ⇒ Object
- #pandoc_ruby_to_html(content, options = {}) ⇒ Object
- #pandoc_ruby_to_html_incremental(content, options = {}) ⇒ Object
-
#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.
- #pandoc_ruby_to_s5_incremental(content, options = {}) ⇒ Object
- #rdiscount_to_html(content, options = {}) ⇒ Object
- #rdiscount_version ⇒ Object
- #redcarpet_to_html(content, options = {}) ⇒ Object
- #redcarpet_version ⇒ Object
- #rpeg_markdown_to_html(content, options = {}) ⇒ Object
Instance Method Details
#bluecloth_to_html(content, options = {}) ⇒ Object
8 9 10 11 12 |
# File 'lib/markdown/engines/bluecloth.rb', line 8 def bluecloth_to_html( content, ={} ) puts " Converting Markdown-text (#{content.length} bytes) to HTML using library bluecloth..." BlueCloth.new( content ).to_html end |
#bluecloth_version ⇒ Object
4 5 6 |
# File 'lib/markdown/engines/bluecloth.rb', line 4 def bluecloth_version BlueCloth::VERSION end |
#kramdown_to_html(content, options = {}) ⇒ Object
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 49 50 51 52 53 54 55 56 57 |
# File 'lib/markdown/engines/kramdown.rb', line 8 def kramdown_to_html( content, ={} ) h = {} # todo: find an easier (more generic?) way to setup hash - possible? h[ :auto_ids ] = .fetch( 'auto_ids', nil ) if .fetch( 'auto_ids', nil ) h[ :footnote_nr ] = .fetch( 'footnote_nr',nil ) if .fetch( 'footnote_nr', nil ) h[ :entity_output ] = .fetch( 'entity_output',nil ) if .fetch( 'entity_output', nil ) h[ :toc_levels ] = .fetch( 'toc_levels',nil ) if .fetch( 'toc_levels', nil ) h[ :smart_quotes ] = .fetch( 'smart_quotes',nil ) if .fetch( 'smart_quotes', nil ) = .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 # todo: check content size and newlines # check banner option? # only add banner if some newlines and size > treshold? =<<EOS <!-- === begin markdown block === generated by #{Markdown.} on #{Time.now} with Markdown engine kramdown (#{Kramdown::VERSION}) using options #{h.to_json} --> EOS =<<EOS <!-- === end markdown block === --> EOS content = + content + end # if show_banner content end |
#kramdown_version ⇒ Object
4 5 6 |
# File 'lib/markdown/engines/kramdown.rb', line 4 def kramdown_version Kramdown::VERSION end |
#maruku_to_html(content, options = {}) ⇒ Object
8 9 10 11 12 |
# File 'lib/markdown/engines/maruku.rb', line 8 def maruku_to_html( content, ={} ) puts " Converting Markdown-text (#{content.length} bytes) to HTML using library maruku..." Maruku.new( content, {:on_error => :raise} ).to_html end |
#maruku_version ⇒ Object
4 5 6 |
# File 'lib/markdown/engines/maruku.rb', line 4 def maruku_version Maruku::VERSION 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, ={} ) 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, ={} ) 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, ={} ) 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, ={} ) 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
8 9 10 11 12 |
# File 'lib/markdown/engines/rdiscount.rb', line 8 def rdiscount_to_html( content, ={} ) puts " Converting Markdown-text (#{content.length} bytes) to HTML using library rdiscount..." RDiscount.new( content ).to_html end |
#rdiscount_version ⇒ Object
4 5 6 |
# File 'lib/markdown/engines/rdiscount.rb', line 4 def rdiscount_version RDiscount::VERSION end |
#redcarpet_to_html(content, options = {}) ⇒ Object
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 49 50 51 |
# File 'lib/markdown/engines/redcarpet.rb', line 8 def redcarpet_to_html( content, ={} ) ## NB: uses redcarpet2 # # see https://github.com/tanoku/redcarpet extensions_ary = .fetch( 'extensions', [] ) = .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 # todo: check content size and newlines # check banner option? # only add banner if some newlines and size > treshold? =<<EOS <!-- === begin markdown block === generated by #{Markdown.} on #{Time.now} with Markdown engine redcarpet (#{Redcarpet::VERSION}) w/ HTML render using extensions: #{extensions_ary.to_json} --> EOS =<<EOS <!-- === end markdown block === --> EOS content = + content + end # if show_banner content end |
#redcarpet_version ⇒ Object
4 5 6 |
# File 'lib/markdown/engines/redcarpet.rb', line 4 def redcarpet_version Redcarpet::VERSION 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, ={} ) puts " Converting Markdown-text (#{content.length} bytes) to HTML using library rpeg_markdown..." PEGMarkdown.new( content ).to_html end |