Sha256: 78b3c9822d7d0bc928e42b61d2df03f9f8513ce498cf78c5837ae9835d4bb10c

Contents?: true

Size: 375 Bytes

Versions: 1

Compression:

Stored size: 375 Bytes

Contents

AutoHtml.add_filter(:simple_format) do |text|
  start_tag = "<p>".html_safe
  text = text.to_s.dup
  text.gsub!(/\r\n?/, "\n")                    # \r\n and \r -> \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.html_safe.safe_concat("</p>")
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
galetahub-auto_html-1.0.1 lib/auto_html/filters/simple_format.rb