Module: MarkitupHelper

Defined in:
app/helpers/rails_markitup/markitup_helper.rb

Instance Method Summary collapse

Instance Method Details

#markdown(text, style = "bright") ⇒ Object



3
4
5
6
# File 'app/helpers/rails_markitup/markitup_helper.rb', line 3

def markdown(text, style="bright")
  options = [:hard_wrap, :filter_html, :autolink, :no_intraemphasis, :fenced_code, :gh_blockcode]
  (:div, :class => "#{style}"){syntax_highlighter(Redcarpet.new(text, *options).to_html).html_safe}
end

#syntax_highlighter(html) ⇒ Object



9
10
11
12
13
14
15
# File 'app/helpers/rails_markitup/markitup_helper.rb', line 9

def syntax_highlighter(html)
  doc = Nokogiri::HTML(html)
  doc.search("//pre[@lang]").each do |pre|
    pre.replace Albino.colorize(pre.text.rstrip, pre[:lang])
  end
  doc.to_s
end