module PettanrSimpleFormat::RendererModule

Public Instance Methods

render() click to toggle source
# File lib/pettanr_simple_format.rb, line 5
def render
   self.render_simple_format(self.content)
end
render_simple_format(text) click to toggle source
# File lib/pettanr_simple_format.rb, line 9
def render_simple_format text
  #text = Sanitize.clean(text.to_s, Sanitize::Config::RESTRICTED)
  text = ERB::Util.html_escape(text.to_s)
  start_tag = '<p>'
  text.gsub!(/\r\n?/, "\n")
  text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}")  # 2+ newline  -> paragraph
  text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline   -> br
  text.insert 0, start_tag
  text.concat("</p>")
  text
end