Sha256: 5771edb1c858503659885f99e20651d079a5baf239b6e3d086c30cc63fcf3bfe

Contents?: true

Size: 902 Bytes

Versions: 9

Compression:

Stored size: 902 Bytes

Contents

# frozen_string_literal: true

module EditorJs
  module Blocks
    class ParagraphBlock < Base
      def schema
        YAML.safe_load(<<~YAML)
          type: object
          additionalProperties: false
          properties:
            text:
              type: string
        YAML
      end

      def render(_options = {})
        content_tag(:div, class: css_name) { data['text'].html_safe }
      end

      def sanitize!
        safe_tags = {
          'b' => nil,
          'i' => nil,
          'a' => ['href'],
          'mark' => ['class'],
          'code' => ['class']
        }

        data['text'] = Sanitize.fragment(
          data['text'],
          elements: safe_tags.keys,
          attributes: safe_tags.select {|k, v| v},
          remove_contents: true
        )
      end

      def plain
        decode_html(Sanitize.fragment data['text']).strip
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
editor_js-0.3.1 lib/editor_js/blocks/paragraph_block.rb
editor_js-0.3.0 lib/editor_js/blocks/paragraph_block.rb
editor_js-0.2.5 lib/editor_js/blocks/paragraph_block.rb
editor_js-0.2.4 lib/editor_js/blocks/paragraph_block.rb
editor_js-0.2.3 lib/editor_js/blocks/paragraph_block.rb
editor_js-0.2.2 lib/editor_js/blocks/paragraph_block.rb
editor_js-0.2.1 lib/editor_js/blocks/paragraph_block.rb
editor_js-0.2.0 lib/editor_js/blocks/paragraph_block.rb
editor_js-0.1.0 lib/editor_js/blocks/paragraph_block.rb