class EditorJs::Blocks::QuoteBlock

quote block

Public Instance Methods

plain() click to toggle source
# File lib/editor_js/blocks/quote_block.rb, line 57
def plain
  string = [
    Sanitize.fragment(data['text']).strip,
    Sanitize.fragment(data['caption']).strip
  ].join(', ')
  decode_html(string)
end
render(_options = {}) click to toggle source
# File lib/editor_js/blocks/quote_block.rb, line 21
def render(_options = {})
  text = data['text'].html_safe
  caption = data['caption'].presence&.html_safe

  content_tag :div, class: css_name do
    html_str = content_tag :div, text, class: "#{css_name}__text"
    html_str << content_tag(:div, caption, class: "#{css_name}__caption") if caption
    html_str
  end
end
safe_tags() click to toggle source
# File lib/editor_js/blocks/quote_block.rb, line 32
def safe_tags
  {
    'b' => nil,
    'i' => nil,
    'u' => ['class'],
    'del' => ['class'],
    'a' => ['href'],
    'mark' => ['class'],
    'code' => ['class'],
    'br' => nil
  }
end
sanitize!() click to toggle source
# File lib/editor_js/blocks/quote_block.rb, line 45
def sanitize!
  %w[text caption].each do |key|
    data[key] = Sanitize.fragment(
      data[key],
      elements: safe_tags.keys,
      attributes: safe_tags.select { |_k, v| v },
      remove_contents: false
    )
  end
  data['alignment'] = Sanitize.fragment(data['alignment'], remove_contents: true)
end
schema() click to toggle source
# File lib/editor_js/blocks/quote_block.rb, line 7
      def schema
        YAML.safe_load(<<~YAML)
          type: object
          additionalProperties: false
          properties:
            text:
              type: string
            caption:
              type: string
            alignment:
              type: string
        YAML
      end