class EditorJs::Blocks::ListBlock

list block

Public Instance Methods

plain() click to toggle source
# File lib/editor_js/blocks/list_block.rb, line 56
def plain
  data['items'].map do |text|
    decode_html(Sanitize.fragment(text)).strip
  end.join(', ')
end
render(_options = {}) click to toggle source
# File lib/editor_js/blocks/list_block.rb, line 22
def render(_options = {})
  tag = data['style'] == 'unordered' ? :ul : :ol
  content_tag(tag, class: css_name) do
    children_tag_string = ''
    data['items'].each do |v|
      children_tag_string += content_tag(:li, v.html_safe)
    end
    children_tag_string.html_safe
  end
end
safe_tags() click to toggle source
# File lib/editor_js/blocks/list_block.rb, line 33
def safe_tags
  {
    'b' => nil,
    'i' => nil,
    'u' => ['class'],
    'del' => ['class'],
    'a' => ['href'],
    'mark' => ['class'],
    'code' => ['class']
  }
end
sanitize!() click to toggle source
# File lib/editor_js/blocks/list_block.rb, line 45
def sanitize!
  data['items'] = data['items'].map do |text|
    Sanitize.fragment(
      text,
      elements: safe_tags.keys,
      attributes: safe_tags.select { |_k, v| v },
      remove_contents: true
    )
  end
end
schema() click to toggle source
# File lib/editor_js/blocks/list_block.rb, line 7
      def schema
        YAML.safe_load(<<~YAML)
          type: object
          additionalProperties: false
          properties:
            style:
              type: string
              pattern: ^(un)?ordered$
            items:
              type: array
              items:
                type: string
        YAML
      end