Sha256: 98cb28274608b49b2f17688346c249238a55efeace6ce130b9387cce1a753d62

Contents?: true

Size: 1.44 KB

Versions: 7

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

require_relative '../block/checkboxes'
require_relative '../block/radio_buttons'
require_relative '../block/textarea'

require_relative '../inline/input'

module Redcarpet
  module Form
    module Extension
      module Render
        # Custom HTML render
        class HTML < Redcarpet::Render::HTML
          def paragraph(text)
            process_custom_tags(text.strip)
          end

          private

          # Processes custom tags (inline tags and block tags)
          def process_custom_tags(text)
            text = CGI.unescape_html(text)

            # Inline tags
            inline_tags.each do |klass|
              text.gsub!(klass.pattern) { |sub| klass.html(sub) }
            end

            # Block tags (replace entire line)
            block_tags.each do |klass|
              next unless text.match?(klass.pattern)

              return klass.html(text.scan(klass.pattern))
            end

            "<p>#{text}</p>\n"
          end

          # List of inline tags
          def inline_tags
            [
              Redcarpet::Form::Extension::Inline::Input
            ]
          end

          # List of block tags
          def block_tags
            [
              Redcarpet::Form::Extension::Block::Checkboxes,
              Redcarpet::Form::Extension::Block::RadioButtons,
              Redcarpet::Form::Extension::Block::Textarea
            ]
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
redcarpet-form-extension-0.4.0 lib/redcarpet/form/extension/render/html.rb
redcarpet-form-extension-0.3.0 lib/redcarpet/form/extension/render/html.rb
redcarpet-form-extension-0.2.1 lib/redcarpet/form/extension/render/html.rb
redcarpet-form-extension-0.2.0 lib/redcarpet/form/extension/render/html.rb
redcarpet-form-extension-0.1.3 lib/redcarpet/form/extension/render/html.rb
redcarpet-form-extension-0.1.2 lib/redcarpet/form/extension/render/html.rb
redcarpet-form-extension-0.1.0 lib/redcarpet/form/extension/render/html.rb