Class: TextUtils::Markdown

Inherits:
Processor show all
Defined in:
lib/text_utils/markdown.rb

Constant Summary collapse

DEFAULT_OPTIONS =
[:autolink, :lax_htmlblock, :smart, :tables, :xhtml, :fenced_code, :strikethrough, :hard_wrap]

Instance Method Summary collapse

Constructor Details

#initialize(processor = nil, options = nil) ⇒ Markdown

Returns a new instance of Markdown.



4
5
6
7
# File 'lib/text_utils/markdown.rb', line 4

def initialize processor = nil, options = nil
  super processor
  @options = options || DEFAULT_OPTIONS
end

Instance Method Details

#call(data, env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/text_utils/markdown.rb', line 9

def call data, env
  if env[:format] == :markdown
    require 'redcarpet'

    data = fix_new_lines data do |data|
      markdown = Redcarpet.new(data, *@options)
      markdown.to_html
    end
  end

  call_next data, env
end