Sha256: d4743176d962e0c79ec6c136857c0b0bbc393161a6e21d66bdffc7a033a7d69a
Contents?: true
Size: 1.68 KB
Versions: 1
Compression:
Stored size: 1.68 KB
Contents
# frozen_string_literal: true module EditorJs module Blocks class HTMLwithCodeRay < Redcarpet::Render::HTML def block_code(code, language) CodeRay.scan(code, language || :text).div(css: :class) end def list_item(text, list_type) if text.start_with?("[x]", "[X]") text[0..2] = %(<input type='checkbox' checked='checked' disabled>) elsif text.start_with?("[ ]") text[0..2] = %(<input type='checkbox' disabled>) end %(<li>#{text}</li>) end end class MarkdownBlock < Base def schema YAML.safe_load(<<~YAML) type: object additionalProperties: false properties: text: type: string YAML end def render(_options = {}) content_tag :div, class: css_name do content_text = data['text'] || '' render_options = { escape_html: true, hard_wrap: true, with_toc_data: true, link_attributes: { rel: 'nofollow', target: '_blank' } } renderer = HTMLwithCodeRay.new(render_options) options = { autolink: true, fenced_code_blocks: true, lax_spacing: true, no_intra_emphasis: true, strikethrough: true, tables: true, superscript: true, highlight: true, quote: true, footnotes: true } markdown_to_html = Redcarpet::Markdown.new(renderer, options) markdown_to_html.render(content_text).html_safe end end def plain data['text'].strip end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
editor_js-0.1.0 | lib/editor_js/blocks/markdown_block.rb |