Class: EditorJs::Blocks::MarkdownBlock

Inherits:
Base
  • Object
show all
Defined in:
lib/editor_js/blocks/markdown_block.rb

Overview

markdown block

Constant Summary

Constants inherited from Base

Base::InvalidBlockDataError, Base::InvalidBlockTypeError

Instance Attribute Summary

Attributes inherited from Base

#output_buffer, #raw

Instance Method Summary collapse

Methods inherited from Base

#css_name, #data, #decode_html, inherited, #initialize, load, #output, registry, type, #type, #valid?

Constructor Details

This class inherits a constructor from EditorJs::Blocks::Base

Instance Method Details

#plainObject



45
46
47
# File 'lib/editor_js/blocks/markdown_block.rb', line 45

def plain
  data['text'].strip
end

#render(_options = {}) ⇒ Object

rouge: syntax highlighter github.com/rouge-ruby/rouge/ spsarolkar.github.io/rouge-theme-preview/ shell: rougify help style # Get some CSS Rouge::Themes::Base16.mode(:light).render(scope: ‘.highlight’) # Or use Theme#find with string input Rouge::Theme.find(‘base16.light’).render(scope: ‘.highlight’)



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/editor_js/blocks/markdown_block.rb', line 32

def render(_options = {})
   :div, class: css_name do
    content_text = data['text'] || ''
    CommonMarker::Rouge.render_html(
      content_text,
      %i[UNSAFE FOOTNOTES STRIKETHROUGH_DOUBLE_TILDE],
      %i[UNSAFE GITHUB_PRE_LANG HARDBREAKS TABLE_PREFER_STYLE_ATTRIBUTES FULL_INFO_STRING FOOTNOTES],
      %i[table strikethrough tasklist tagfilter],
      formatter: Rouge::Formatters::HTMLLegacy.new(inline_theme: 'github')
    ).html_safe
  end
end

#sanitize!Object



7
# File 'lib/editor_js/blocks/markdown_block.rb', line 7

def sanitize!; end

#schemaObject



9
10
11
12
13
14
15
16
17
# File 'lib/editor_js/blocks/markdown_block.rb', line 9

def schema
  YAML.safe_load(<<~YAML)
    type: object
    additionalProperties: false
    properties:
      text:
        type: string
  YAML
end