class RenderEditorjs::Blocks::List

Render for github.com/editor-js/nested-list

Constants

SAFE_TAGS

TODO: Consider extract it and the sanitize method with the other on Paragraph block to the DefaultRenderer

SCHEMA

Attributes

options[R]

Public Instance Methods

render(data) click to toggle source
# File lib/render_editorjs/blocks/list.rb, line 40
def render(data)
  return unless valid?(data)

  tag = data["style"] == "unordered" ? :ul : :ol
  render_list(tag, data["items"])
end
render_list(tag, items) click to toggle source
# File lib/render_editorjs/blocks/list.rb, line 47
def render_list(tag, items)
  return "" unless items

  content_tag(tag) do
    children_tag_string = ""
    items.each do |v|
      item = sanitize(v["content"])
      item << render_list(tag, v["items"]) if v["items"]
      children_tag_string += content_tag(:li, item.html_safe)
    end
    children_tag_string.html_safe
  end
end
sanitize(text) click to toggle source
# File lib/render_editorjs/blocks/list.rb, line 61
def sanitize(text)
  Sanitize.fragment(
    text,
    elements: SAFE_TAGS.keys,
    attributes: SAFE_TAGS.select { |_k, v| v },
    remove_contents: true
  )
end