Class: Formol::Formatters::Redcarpet::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/formol/formatters/redcarpet/formatter.rb

Instance Method Summary collapse

Constructor Details

#initializeFormatter

Returns a new instance of Formatter.



8
9
10
11
12
13
14
15
16
# File 'lib/formol/formatters/redcarpet/formatter.rb', line 8

def initialize
  @renderer = SyntaxHighlighter.new(:hard_wrap    => true,
                                    :filter_html  => true)
  @processor = ::Redcarpet::Markdown.new(@renderer, :fenced_code_blocks   => true,
                                                    :no_intra_emphasis    => true,
                                                    :autolink             => true,
                                                    :space_after_headers  => false,
                                                    :superscript          => false)
end

Instance Method Details

#quote(text) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/formol/formatters/redcarpet/formatter.rb', line 22

def quote(text)
  quoted_text = ""
  
  text.split("\n").each_with_index do |l|
    quoted_text << '> ' if (l.strip.blank? || l.start_with?('>'))
    quoted_text << l
    quoted_text << "\n"
  end
  
  quoted_text
end

#to_html(text) ⇒ Object



18
19
20
# File 'lib/formol/formatters/redcarpet/formatter.rb', line 18

def to_html(text)
  @processor.render(text).html_safe
end