class EditorJs::Blocks::HeaderBlock

header_block

Public Instance Methods

plain() click to toggle source
# File lib/editor_js/blocks/header_block.rb, line 45
def plain
  decode_html data['text'].strip
end
render(_options = {}) click to toggle source
# File lib/editor_js/blocks/header_block.rb, line 29
def render(_options = {})
  alignment = data['alignment']
  class_name_str = css_name
  if alignment.present?
    class_name_str = [
      class_name_str,
      css_name("__#{alignment}")
    ].join(' ')
  end
  content_tag(:"h#{data['level']}", data['text'].html_safe, class: class_name_str)
end
sanitize!() click to toggle source
# File lib/editor_js/blocks/header_block.rb, line 41
def sanitize!
  data['text'] = Sanitize.fragment(data['text'], remove_contents: true).strip
end
schema() click to toggle source
# File lib/editor_js/blocks/header_block.rb, line 7
      def schema
        YAML.safe_load(<<~YAML)
          type: object
          additionalProperties: false
          properties:
            text:
              type: string
            level:
              type: number
              enum: [1,2,3,4,5,6]
            alignment:
              type: string
              enum:
                - align-left
                - align-center
                - align-right
          required:
          - text
          - level
        YAML
      end