Sha256: a34c5755839a43652c5fb288150d5b22921525c364f6cd2c0198043d04982040

Contents?: true

Size: 497 Bytes

Versions: 4

Compression:

Stored size: 497 Bytes

Contents

# frozen_string_literal: true

module AutoHtml
  # SimpleFormat filter
  class SimpleFormat
    def call(text)
      paragraphs = split_paragraphs(text)
      paragraphs.map! do |paragraph|
        TagHelper.tag(:p) { paragraph }
      end.join("\n\n")
    end

    private

    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
auto_html-2.2.0 lib/auto_html/simple_format.rb
auto_html-2.1.1 lib/auto_html/simple_format.rb
auto_html-2.1.0 lib/auto_html/simple_format.rb
auto_html-2.0.2 lib/auto_html/simple_format.rb