Class: RenderEditorjs::Blocks::Header
- Defined in:
- lib/render_editorjs/blocks/header.rb
Overview
Compatible with github.com/editor-js/header
Constant Summary collapse
- 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: - left - center - right required: - text - level YAML
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#render(data) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/render_editorjs/blocks/header.rb', line 27 def render(data) return unless valid?(data) alignment = data["alignment"] css_class = alignment ? "align-#{alignment}" : nil content_tag(:"h#{data["level"]}", sanitize(data["text"]).html_safe, class: css_class) end |
#sanitize(text) ⇒ Object
35 36 37 |
# File 'lib/render_editorjs/blocks/header.rb', line 35 def sanitize(text) Sanitize.fragment(text, remove_contents: true).strip end |