editor_js 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a00ab346b57a44f9fd23bcdca062aa86f0cee25326a5db5e810d193129498a7
4
- data.tar.gz: 3e96bc0177d267807ad49915cd2eebb312bb29789931da69ed71cdb58f48dedc
3
+ metadata.gz: d4b38e7aebd2e2208a0d8ab1844758d90d14494e01904909654b4f7ba7805d39
4
+ data.tar.gz: '0198768ae3694054f082a2f10e8c30475c14a9812318f023ca964bb44d928c53'
5
5
  SHA512:
6
- metadata.gz: e65a5f80e1e92a752d39c01a1b72d869d597e12aa541f7790c08d84f3ba84d543f39d74a5758d3a2d54eef8fde9fb32bd8ee90b4a0e5949f044946e27945841a
7
- data.tar.gz: af6f3ec9825b66dcadabfb05872de9dcc366be87382997dc468dacdf0da9132e4ca02028ffc307c841ae124a948d72ad42546103db7682caee0c5981ea6e6c21
6
+ metadata.gz: e84f93404ea3818ea954c13a196c89de8078f9939e13b44a123f2e044fe132dbba0719a8c705ff4654e4b247877fbc9adab73ecd5f5cab92a7c28ad87fcd84cb
7
+ data.tar.gz: 42938bef7744867af9d467343d5871020b350a3010c86868ddfc59935b0039b1e77519223997976afacc0c804e5ad12841f75dede91179c52be3e79ebbaaeb0d
data/Gemfile.lock CHANGED
@@ -1,85 +1,87 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- editor_js (0.3.5)
4
+ editor_js (0.3.6)
5
5
  actionview (>= 4)
6
6
  activesupport (>= 4)
7
- coderay (~> 1.1, >= 1.1.2)
7
+ commonmarker (~> 0.21.2)
8
8
  htmlentities (~> 4.3, >= 4.3.4)
9
9
  json-schema (~> 2)
10
- redcarpet (~> 3.5)
10
+ rouge (~> 3.26)
11
11
  sanitize (~> 5.1)
12
12
 
13
13
  GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
- actionview (6.0.3.2)
17
- activesupport (= 6.0.3.2)
16
+ actionview (6.1.4)
17
+ activesupport (= 6.1.4)
18
18
  builder (~> 3.1)
19
19
  erubi (~> 1.4)
20
20
  rails-dom-testing (~> 2.0)
21
21
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
22
- activesupport (6.0.3.2)
22
+ activesupport (6.1.4)
23
23
  concurrent-ruby (~> 1.0, >= 1.0.2)
24
- i18n (>= 0.7, < 2)
25
- minitest (~> 5.1)
26
- tzinfo (~> 1.1)
27
- zeitwerk (~> 2.2, >= 2.2.2)
28
- addressable (2.7.0)
24
+ i18n (>= 1.6, < 2)
25
+ minitest (>= 5.1)
26
+ tzinfo (~> 2.0)
27
+ zeitwerk (~> 2.3)
28
+ addressable (2.8.0)
29
29
  public_suffix (>= 2.0.2, < 5.0)
30
- ast (2.4.0)
30
+ ast (2.4.2)
31
31
  builder (3.2.4)
32
- coderay (1.1.2)
33
- concurrent-ruby (1.1.6)
32
+ coderay (1.1.3)
33
+ commonmarker (0.21.2)
34
+ ruby-enum (~> 0.5)
35
+ concurrent-ruby (1.1.9)
34
36
  crass (1.0.6)
35
- diff-lcs (1.3)
36
- docile (1.3.2)
37
- erubi (1.9.0)
37
+ diff-lcs (1.4.4)
38
+ docile (1.4.0)
39
+ erubi (1.10.0)
38
40
  htmlentities (4.3.4)
39
- i18n (1.8.3)
41
+ i18n (1.8.10)
40
42
  concurrent-ruby (~> 1.0)
41
43
  jaro_winkler (1.5.4)
42
- json (2.3.0)
44
+ json (2.5.1)
43
45
  json-schema (2.8.1)
44
46
  addressable (>= 2.4)
45
- loofah (2.6.0)
47
+ loofah (2.11.0)
46
48
  crass (~> 1.0.2)
47
49
  nokogiri (>= 1.5.9)
48
50
  method_source (0.9.2)
49
- mini_portile2 (2.4.0)
50
- minitest (5.14.1)
51
- nokogiri (1.10.10)
52
- mini_portile2 (~> 2.4.0)
53
- nokogumbo (2.0.2)
51
+ minitest (5.14.4)
52
+ nokogiri (1.12.2-x86_64-darwin)
53
+ racc (~> 1.4)
54
+ nokogumbo (2.0.5)
54
55
  nokogiri (~> 1.8, >= 1.8.4)
55
- parallel (1.19.1)
56
- parser (2.6.5.0)
57
- ast (~> 2.4.0)
56
+ parallel (1.20.1)
57
+ parser (3.0.2.0)
58
+ ast (~> 2.4.1)
58
59
  pry (0.12.2)
59
60
  coderay (~> 1.1.0)
60
61
  method_source (~> 0.9.0)
61
- public_suffix (4.0.5)
62
+ public_suffix (4.0.6)
63
+ racc (1.5.2)
62
64
  rails-dom-testing (2.0.3)
63
65
  activesupport (>= 4.2.0)
64
66
  nokogiri (>= 1.6)
65
67
  rails-html-sanitizer (1.3.0)
66
68
  loofah (~> 2.3)
67
69
  rainbow (3.0.0)
68
- rake (13.0.1)
69
- redcarpet (3.5.0)
70
- rspec (3.9.0)
71
- rspec-core (~> 3.9.0)
72
- rspec-expectations (~> 3.9.0)
73
- rspec-mocks (~> 3.9.0)
74
- rspec-core (3.9.0)
75
- rspec-support (~> 3.9.0)
76
- rspec-expectations (3.9.0)
70
+ rake (13.0.6)
71
+ rouge (3.26.0)
72
+ rspec (3.10.0)
73
+ rspec-core (~> 3.10.0)
74
+ rspec-expectations (~> 3.10.0)
75
+ rspec-mocks (~> 3.10.0)
76
+ rspec-core (3.10.1)
77
+ rspec-support (~> 3.10.0)
78
+ rspec-expectations (3.10.1)
77
79
  diff-lcs (>= 1.2.0, < 2.0)
78
- rspec-support (~> 3.9.0)
79
- rspec-mocks (3.9.0)
80
+ rspec-support (~> 3.10.0)
81
+ rspec-mocks (3.10.2)
80
82
  diff-lcs (>= 1.2.0, < 2.0)
81
- rspec-support (~> 3.9.0)
82
- rspec-support (3.9.0)
83
+ rspec-support (~> 3.10.0)
84
+ rspec-support (3.10.2)
83
85
  rubocop (0.77.0)
84
86
  jaro_winkler (~> 1.5.1)
85
87
  parallel (~> 1.10)
@@ -87,8 +89,10 @@ GEM
87
89
  rainbow (>= 2.2.2, < 4.0)
88
90
  ruby-progressbar (~> 1.7)
89
91
  unicode-display_width (>= 1.4.0, < 1.7)
90
- ruby-progressbar (1.10.1)
91
- sanitize (5.2.1)
92
+ ruby-enum (0.9.0)
93
+ i18n
94
+ ruby-progressbar (1.11.0)
95
+ sanitize (5.2.3)
92
96
  crass (~> 1.0.2)
93
97
  nokogiri (>= 1.8.0)
94
98
  nokogumbo (~> 2.0)
@@ -97,14 +101,13 @@ GEM
97
101
  json (>= 1.8, < 3)
98
102
  simplecov-html (~> 0.10.0)
99
103
  simplecov-html (0.10.2)
100
- thread_safe (0.3.6)
101
- tzinfo (1.2.7)
102
- thread_safe (~> 0.1)
103
- unicode-display_width (1.6.0)
104
- zeitwerk (2.3.1)
104
+ tzinfo (2.0.4)
105
+ concurrent-ruby (~> 1.0)
106
+ unicode-display_width (1.6.1)
107
+ zeitwerk (2.4.2)
105
108
 
106
109
  PLATFORMS
107
- ruby
110
+ x86_64-darwin-20
108
111
 
109
112
  DEPENDENCIES
110
113
  bundler (~> 2.0)
@@ -116,4 +119,4 @@ DEPENDENCIES
116
119
  simplecov (~> 0.17.1)
117
120
 
118
121
  BUNDLED WITH
119
- 2.1.4
122
+ 2.2.25
data/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/editor_js.svg)](https://badge.fury.io/rb/editor_js) [![Build Status](https://travis-ci.org/xiaohui-zhangxh/editor_js.svg?branch=master)](https://travis-ci.org/xiaohui-zhangxh/editor_js) [![Maintainability](https://api.codeclimate.com/v1/badges/e26bf8e27fb3a33735fd/maintainability)](https://codeclimate.com/github/xiaohui-zhangxh/editor_js/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/e26bf8e27fb3a33735fd/test_coverage)](https://codeclimate.com/github/xiaohui-zhangxh/editor_js/test_coverage) ![Downloads](https://ruby-gem-downloads-badge.herokuapp.com/editor_js?type=total)
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/editor_js`. To experiment with that code, run `bin/console` for an interactive prompt.
6
-
7
- TODO: Delete this and the text above, and describe your gem
5
+ A Ruby renderer for EditorJS https://editorjs.io/
8
6
 
9
7
  ## Installation
10
8
 
data/editor_js.gemspec CHANGED
@@ -27,11 +27,11 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.add_dependency 'actionview', '>= 4'
29
29
  spec.add_dependency 'activesupport', '>= 4'
30
+ spec.add_dependency 'commonmarker', '~> 0.21.2'
31
+ spec.add_dependency 'htmlentities', '~> 4.3', '>= 4.3.4'
30
32
  spec.add_dependency 'json-schema', '~> 2'
33
+ spec.add_dependency 'rouge', '~> 3.26'
31
34
  spec.add_dependency 'sanitize', '~> 5.1'
32
- spec.add_dependency 'htmlentities', '~> 4.3', '>= 4.3.4'
33
- spec.add_dependency 'redcarpet', '~> 3.5'
34
- spec.add_dependency 'coderay', '~> 1.1', '>= 1.1.2'
35
35
  spec.add_development_dependency "bundler", "~> 2.0"
36
36
  spec.add_development_dependency "rake", "~> 13.0"
37
37
  spec.add_development_dependency "rspec", "~> 3.0"
@@ -0,0 +1,12 @@
1
+ class CommonMarker::CustomHtmlRenderer < CommonMarker::HtmlRenderer
2
+ def tasklist(node)
3
+ return '' unless tasklist?(node)
4
+
5
+ state = if checked?(node)
6
+ 'checked="" disabled=""'
7
+ else
8
+ 'disabled=""'
9
+ end
10
+ " class=\"task-list-item\"><input type=\"checkbox\" #{state} /"
11
+ end
12
+ end
@@ -0,0 +1,66 @@
1
+ require 'common_marker/custom_html_render'
2
+
3
+ # frozen_string_literal: true
4
+ module CommonMarker
5
+ # rouge
6
+ module Rouge
7
+ module_function
8
+
9
+ def render_doc(text, cmark_options = :DEFAULT, extensions = [], **cmr_options)
10
+ cmark = cmr_options[:cmark_class] || ::CommonMarker
11
+
12
+ ast = cmark.render_doc(text, cmark_options, extensions)
13
+ process_ast(ast, cmr_options)
14
+ ast
15
+ end
16
+
17
+ def render_html(text, cmark_options = :DEFAULT, render_options = :UNSAFE, extensions = [], **cmr_options)
18
+ doc = render_doc(text, cmark_options, extensions, **cmr_options)
19
+ CommonMarker::CustomHtmlRenderer.new(options: render_options, extensions: extensions).render(doc)
20
+ # doc.to_html(render_options)
21
+ end
22
+
23
+ def process_ast(ast, cmr_options)
24
+ ast.walk do |node|
25
+ if node.type == :code_block
26
+ next if node.fence_info == ''
27
+
28
+ source = node.string_content
29
+
30
+ lexer = ::Rouge::Lexer.find_fancy(node.fence_info) || ::Rouge::Lexers::PlainText.new
31
+
32
+ formatter_class = cmr_options[:formatter_class]
33
+ formatter = cmr_options[:formatter]
34
+
35
+ # support format accepting class for a time being
36
+ if formatter.is_a? Class
37
+ formatter_class ||= formatter
38
+ formatter = nil
39
+ end
40
+
41
+ formatter_class ||= ::Rouge::Formatters::HTML
42
+
43
+ formatter ||= formatter_class.new(cmr_options[:options] || {})
44
+
45
+ html = '<div class="highlighter-rouge language-' + CGI.escapeHTML(node.fence_info) + '">' + formatter.format(lexer.lex(source)) + '</div>'
46
+
47
+ new_node = ::CommonMarker::Node.new(:html)
48
+ new_node.string_content = html
49
+
50
+ node.insert_before(new_node)
51
+ node.delete
52
+ elsif node.type == :html
53
+ node.string_content = ::Sanitize.fragment(
54
+ node.string_content,
55
+ ::Sanitize::Config.merge(
56
+ ::Sanitize::Config::BASIC,
57
+ remove_contents: true
58
+ )
59
+ )
60
+ end
61
+ end
62
+ end
63
+
64
+ private_class_method :process_ast
65
+ end
66
+ end
data/lib/editor_js.rb CHANGED
@@ -8,8 +8,9 @@ require 'action_view/helpers'
8
8
  require 'json-schema'
9
9
  require 'sanitize'
10
10
  require 'htmlentities'
11
- require 'redcarpet'
12
- require 'coderay'
11
+ require 'commonmarker'
12
+ require 'rouge'
13
+ require 'common_marker/rouge'
13
14
  require 'editor_js/version'
14
15
  require 'editor_js/blocks/base'
15
16
  require 'editor_js/blocks/checklist_block'
@@ -4,21 +4,6 @@ module EditorJs
4
4
  module Blocks
5
5
  # markdown block
6
6
  class MarkdownBlock < Base
7
- class HTMLwithCodeRay < Redcarpet::Render::HTML
8
- def block_code(code, language)
9
- CodeRay.scan(code, language || :text).div(css: :class)
10
- end
11
-
12
- def list_item(text, list_type)
13
- if text.start_with?("[x]", "[X]")
14
- text[0..2] = %(<input type='checkbox' checked='checked' disabled>)
15
- elsif text.start_with?("[ ]")
16
- text[0..2] = %(<input type='checkbox' disabled>)
17
- end
18
- %(<li>#{text}</li>)
19
- end
20
- end
21
-
22
7
  def sanitize!; end
23
8
 
24
9
  def schema
@@ -31,33 +16,29 @@ module EditorJs
31
16
  YAML
32
17
  end
33
18
 
19
+ # commonmarker: markdown to html
20
+ # https://github.com/gjtorikian/commonmarker
21
+ # https://github.github.com/gfm/#ordered-list
22
+ # https://meta.stackexchange.com/questions/348746/were-switching-to-commonmark
23
+
24
+ # rouge: syntax highlighter
25
+ # https://github.com/rouge-ruby/rouge/
26
+ # https://spsarolkar.github.io/rouge-theme-preview/
27
+ # shell: rougify help style
28
+ # # Get some CSS
29
+ # Rouge::Themes::Base16.mode(:light).render(scope: '.highlight')
30
+ # # Or use Theme#find with string input
31
+ # Rouge::Theme.find('base16.light').render(scope: '.highlight')
34
32
  def render(_options = {})
35
33
  content_tag :div, class: css_name do
36
34
  content_text = data['text'] || ''
37
-
38
- render_options = {
39
- escape_html: true,
40
- hard_wrap: true,
41
- with_toc_data: true,
42
- link_attributes: { rel: 'nofollow', target: '_blank' }
43
- }
44
- renderer = HTMLwithCodeRay.new(render_options)
45
-
46
- options = {
47
- autolink: true,
48
- fenced_code_blocks: true,
49
- lax_spacing: true,
50
- no_intra_emphasis: true,
51
- strikethrough: true,
52
- tables: true,
53
- superscript: true,
54
- highlight: true,
55
- quote: true,
56
- footnotes: true
57
- }
58
- markdown_to_html = Redcarpet::Markdown.new(renderer, options)
59
-
60
- markdown_to_html.render(content_text).html_safe
35
+ CommonMarker::Rouge.render_html(
36
+ content_text,
37
+ %i[UNSAFE FOOTNOTES STRIKETHROUGH_DOUBLE_TILDE],
38
+ %i[UNSAFE GITHUB_PRE_LANG HARDBREAKS TABLE_PREFER_STYLE_ATTRIBUTES FULL_INFO_STRING FOOTNOTES],
39
+ %i[table strikethrough tasklist tagfilter],
40
+ formatter: Rouge::Formatters::HTMLLegacy.new(inline_theme: 'github')
41
+ ).html_safe
61
42
  end
62
43
  end
63
44
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EditorJs
4
- VERSION = '0.3.5'
4
+ VERSION = '0.3.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: editor_js
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - xiaohui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-14 00:00:00.000000000 Z
11
+ date: 2021-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -39,87 +39,81 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '4'
41
41
  - !ruby/object:Gem::Dependency
42
- name: json-schema
42
+ name: commonmarker
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2'
47
+ version: 0.21.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2'
54
+ version: 0.21.2
55
55
  - !ruby/object:Gem::Dependency
56
- name: sanitize
56
+ name: htmlentities
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '5.1'
61
+ version: '4.3'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 4.3.4
62
65
  type: :runtime
63
66
  prerelease: false
64
67
  version_requirements: !ruby/object:Gem::Requirement
65
68
  requirements:
66
69
  - - "~>"
67
70
  - !ruby/object:Gem::Version
68
- version: '5.1'
71
+ version: '4.3'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 4.3.4
69
75
  - !ruby/object:Gem::Dependency
70
- name: htmlentities
76
+ name: json-schema
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
79
  - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '4.3'
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: 4.3.4
81
+ version: '2'
79
82
  type: :runtime
80
83
  prerelease: false
81
84
  version_requirements: !ruby/object:Gem::Requirement
82
85
  requirements:
83
86
  - - "~>"
84
87
  - !ruby/object:Gem::Version
85
- version: '4.3'
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- version: 4.3.4
88
+ version: '2'
89
89
  - !ruby/object:Gem::Dependency
90
- name: redcarpet
90
+ name: rouge
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '3.5'
95
+ version: '3.26'
96
96
  type: :runtime
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '3.5'
102
+ version: '3.26'
103
103
  - !ruby/object:Gem::Dependency
104
- name: coderay
104
+ name: sanitize
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '1.1'
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: 1.1.2
109
+ version: '5.1'
113
110
  type: :runtime
114
111
  prerelease: false
115
112
  version_requirements: !ruby/object:Gem::Requirement
116
113
  requirements:
117
114
  - - "~>"
118
115
  - !ruby/object:Gem::Version
119
- version: '1.1'
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- version: 1.1.2
116
+ version: '5.1'
123
117
  - !ruby/object:Gem::Dependency
124
118
  name: bundler
125
119
  requirement: !ruby/object:Gem::Requirement
@@ -181,6 +175,8 @@ files:
181
175
  - bin/console
182
176
  - bin/setup
183
177
  - editor_js.gemspec
178
+ - lib/common_marker/custom_html_render.rb
179
+ - lib/common_marker/rouge.rb
184
180
  - lib/editor_js.rb
185
181
  - lib/editor_js/blocks/attaches_block.rb
186
182
  - lib/editor_js/blocks/base.rb
@@ -221,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
217
  - !ruby/object:Gem::Version
222
218
  version: '0'
223
219
  requirements: []
224
- rubygems_version: 3.0.8
220
+ rubygems_version: 3.0.9
225
221
  signing_key:
226
222
  specification_version: 4
227
223
  summary: Ruby gem for editorjs.io text editor