Sha256: 108d881ccff453f61d17fb325e7d0e6b3815e36e5b98a5aca05a50743104d7ee

Contents?: true

Size: 960 Bytes

Versions: 1

Compression:

Stored size: 960 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,
          'u' => ['class'],
          'del' => ['class'],
          '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

1 entries across 1 versions & 1 rubygems

Version Path
editor_js-0.3.2 lib/editor_js/blocks/paragraph_block.rb