Sha256: c7e34c8a786f0284e7e5dceb8d5756ceee1c62de879ca2837987b2278ba895b8

Contents?: true

Size: 562 Bytes

Versions: 64

Compression:

Stored size: 562 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module ContentParsers
    # A parser that searches newline escape sequences in content.
    #
    # The escape sequences `\r\n` and `\r` will be replaced by `\n`.
    #
    # @see BaseParser Examples of how to use a content parser
    class NewlineParser < BaseParser
      ESCAPE_SEQUENCES = ["\r\n", "\r"].freeze
      REGEX = Regexp.union(ESCAPE_SEQUENCES)

      # @return [String] the content with the escape sequences replaced.
      def rewrite
        content.gsub(REGEX, "\n")
      end
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
decidim-core-0.26.8 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.27.4 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.27.3 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.26.7 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.26.5 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.27.2 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.27.1 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.26.4 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.27.0 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.26.3 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.27.0.rc2 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.27.0.rc1 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.26.2 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.26.1 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.26.0 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.26.0.rc2 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.26.0.rc1 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.25.2 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.25.1 lib/decidim/content_parsers/newline_parser.rb
decidim-core-0.25.0 lib/decidim/content_parsers/newline_parser.rb