class AutoHtml::SimpleFormat

SimpleFormat filter

Public Instance Methods

call(text) click to toggle source
# File lib/auto_html/simple_format.rb, line 6
def call(text)
  paragraphs = split_paragraphs(text)
  paragraphs.map! do |paragraph|
    TagHelper.tag(:p) { paragraph }
  end.join("\n\n")
end

Private Instance Methods

split_paragraphs(text) click to toggle source
# File lib/auto_html/simple_format.rb, line 15
def split_paragraphs(text)
  return [] if text.nil? || text.empty?

  text.to_s.gsub(/\r\n?/, "\n").split(/\n\n+/).map! do |t|
    t.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') || t
  end
end