editor_js 0.3.3 → 0.3.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +55 -55
- data/README.md +1 -3
- data/editor_js.gemspec +4 -4
- data/lib/common_marker/custom_html_render.rb +12 -0
- data/lib/common_marker/rouge.rb +66 -0
- data/lib/editor_js.rb +4 -2
- data/lib/editor_js/blocks/attaches_block.rb +1 -0
- data/lib/editor_js/blocks/checklist_block.rb +6 -3
- data/lib/editor_js/blocks/code_block.rb +1 -0
- data/lib/editor_js/blocks/delimiter_block.rb +1 -0
- data/lib/editor_js/blocks/embed_block.rb +1 -0
- data/lib/editor_js/blocks/header_block.rb +1 -0
- data/lib/editor_js/blocks/image_block.rb +1 -0
- data/lib/editor_js/blocks/list_block.rb +6 -3
- data/lib/editor_js/blocks/markdown_block.rb +21 -39
- data/lib/editor_js/blocks/paragraph_block.rb +6 -3
- data/lib/editor_js/blocks/qiniu_image_block.rb +1 -0
- data/lib/editor_js/blocks/quote_block.rb +7 -4
- data/lib/editor_js/blocks/table_block.rb +23 -3
- data/lib/editor_js/blocks/warning_block.rb +61 -0
- data/lib/editor_js/version.rb +1 -1
- metadata +30 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc68a5b437f52314867a5c04726164825c17d4fae12fa60afe079903b776b9ad
|
4
|
+
data.tar.gz: ab4234218fdea2e6fe97f9860366a4122e3553535b0941175ee06ef262538311
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ce06f481e7c0578c6405466ee84a757c4acb2ac7a90c277f4f19bbdfb6f102bb98ea027cf93cf345f0d9f1d0aa42a6d0953fc60c73800b3d50d0f2dae27b32b
|
7
|
+
data.tar.gz: 51a76b6c4af5c00d99752cb06d375b91e74a3be4abef4f325a40b9256ef1a99c321fb74757d3a487dde4ae902bd957cb0689a77a2b4c4d1a365df5e373dfb657
|
data/Gemfile.lock
CHANGED
@@ -1,85 +1,85 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
editor_js (0.3.
|
4
|
+
editor_js (0.3.6.1)
|
5
5
|
actionview (>= 4)
|
6
6
|
activesupport (>= 4)
|
7
|
-
|
7
|
+
commonmarker (~> 0.21.2)
|
8
8
|
htmlentities (~> 4.3, >= 4.3.4)
|
9
9
|
json-schema (~> 2)
|
10
|
-
|
11
|
-
sanitize (~>
|
10
|
+
rouge (~> 3.26)
|
11
|
+
sanitize (~> 6.0)
|
12
12
|
|
13
13
|
GEM
|
14
14
|
remote: https://rubygems.org/
|
15
15
|
specs:
|
16
|
-
actionview (6.
|
17
|
-
activesupport (= 6.
|
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.
|
22
|
+
activesupport (6.1.4)
|
23
23
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
24
|
-
i18n (>=
|
25
|
-
minitest (
|
26
|
-
tzinfo (~>
|
27
|
-
zeitwerk (~> 2.
|
28
|
-
addressable (2.
|
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.
|
30
|
+
ast (2.4.2)
|
31
31
|
builder (3.2.4)
|
32
|
-
coderay (1.1.
|
33
|
-
|
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.
|
36
|
-
docile (1.
|
37
|
-
erubi (1.
|
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.
|
41
|
+
i18n (1.8.10)
|
40
42
|
concurrent-ruby (~> 1.0)
|
41
43
|
jaro_winkler (1.5.4)
|
42
|
-
json (2.
|
44
|
+
json (2.5.1)
|
43
45
|
json-schema (2.8.1)
|
44
46
|
addressable (>= 2.4)
|
45
|
-
loofah (2.
|
47
|
+
loofah (2.12.0)
|
46
48
|
crass (~> 1.0.2)
|
47
49
|
nokogiri (>= 1.5.9)
|
48
50
|
method_source (0.9.2)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
parallel (1.19.1)
|
56
|
-
parser (2.6.5.0)
|
57
|
-
ast (~> 2.4.0)
|
51
|
+
minitest (5.14.4)
|
52
|
+
nokogiri (1.12.3-x86_64-darwin)
|
53
|
+
racc (~> 1.4)
|
54
|
+
parallel (1.20.1)
|
55
|
+
parser (3.0.2.0)
|
56
|
+
ast (~> 2.4.1)
|
58
57
|
pry (0.12.2)
|
59
58
|
coderay (~> 1.1.0)
|
60
59
|
method_source (~> 0.9.0)
|
61
|
-
public_suffix (4.0.
|
60
|
+
public_suffix (4.0.6)
|
61
|
+
racc (1.5.2)
|
62
62
|
rails-dom-testing (2.0.3)
|
63
63
|
activesupport (>= 4.2.0)
|
64
64
|
nokogiri (>= 1.6)
|
65
65
|
rails-html-sanitizer (1.3.0)
|
66
66
|
loofah (~> 2.3)
|
67
67
|
rainbow (3.0.0)
|
68
|
-
rake (13.0.
|
69
|
-
|
70
|
-
rspec (3.
|
71
|
-
rspec-core (~> 3.
|
72
|
-
rspec-expectations (~> 3.
|
73
|
-
rspec-mocks (~> 3.
|
74
|
-
rspec-core (3.
|
75
|
-
rspec-support (~> 3.
|
76
|
-
rspec-expectations (3.
|
68
|
+
rake (13.0.6)
|
69
|
+
rouge (3.26.0)
|
70
|
+
rspec (3.10.0)
|
71
|
+
rspec-core (~> 3.10.0)
|
72
|
+
rspec-expectations (~> 3.10.0)
|
73
|
+
rspec-mocks (~> 3.10.0)
|
74
|
+
rspec-core (3.10.1)
|
75
|
+
rspec-support (~> 3.10.0)
|
76
|
+
rspec-expectations (3.10.1)
|
77
77
|
diff-lcs (>= 1.2.0, < 2.0)
|
78
|
-
rspec-support (~> 3.
|
79
|
-
rspec-mocks (3.
|
78
|
+
rspec-support (~> 3.10.0)
|
79
|
+
rspec-mocks (3.10.2)
|
80
80
|
diff-lcs (>= 1.2.0, < 2.0)
|
81
|
-
rspec-support (~> 3.
|
82
|
-
rspec-support (3.
|
81
|
+
rspec-support (~> 3.10.0)
|
82
|
+
rspec-support (3.10.2)
|
83
83
|
rubocop (0.77.0)
|
84
84
|
jaro_winkler (~> 1.5.1)
|
85
85
|
parallel (~> 1.10)
|
@@ -87,24 +87,24 @@ GEM
|
|
87
87
|
rainbow (>= 2.2.2, < 4.0)
|
88
88
|
ruby-progressbar (~> 1.7)
|
89
89
|
unicode-display_width (>= 1.4.0, < 1.7)
|
90
|
-
ruby-
|
91
|
-
|
90
|
+
ruby-enum (0.9.0)
|
91
|
+
i18n
|
92
|
+
ruby-progressbar (1.11.0)
|
93
|
+
sanitize (6.0.0)
|
92
94
|
crass (~> 1.0.2)
|
93
|
-
nokogiri (>= 1.
|
94
|
-
nokogumbo (~> 2.0)
|
95
|
+
nokogiri (>= 1.12.0)
|
95
96
|
simplecov (0.17.1)
|
96
97
|
docile (~> 1.1)
|
97
98
|
json (>= 1.8, < 3)
|
98
99
|
simplecov-html (~> 0.10.0)
|
99
100
|
simplecov-html (0.10.2)
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
zeitwerk (2.3.1)
|
101
|
+
tzinfo (2.0.4)
|
102
|
+
concurrent-ruby (~> 1.0)
|
103
|
+
unicode-display_width (1.6.1)
|
104
|
+
zeitwerk (2.4.2)
|
105
105
|
|
106
106
|
PLATFORMS
|
107
|
-
|
107
|
+
x86_64-darwin-20
|
108
108
|
|
109
109
|
DEPENDENCIES
|
110
110
|
bundler (~> 2.0)
|
@@ -116,4 +116,4 @@ DEPENDENCIES
|
|
116
116
|
simplecov (~> 0.17.1)
|
117
117
|
|
118
118
|
BUNDLED WITH
|
119
|
-
2.
|
119
|
+
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
|
-
|
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 '
|
31
|
-
spec.add_dependency 'sanitize', '~> 5.1'
|
30
|
+
spec.add_dependency 'commonmarker', '~> 0.21.2'
|
32
31
|
spec.add_dependency 'htmlentities', '~> 4.3', '>= 4.3.4'
|
33
|
-
spec.add_dependency '
|
34
|
-
spec.add_dependency '
|
32
|
+
spec.add_dependency 'json-schema', '~> 2'
|
33
|
+
spec.add_dependency 'rouge', '~> 3.26'
|
34
|
+
spec.add_dependency 'sanitize', '~> 6.0'
|
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 '
|
12
|
-
require '
|
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'
|
@@ -23,6 +24,7 @@ require 'editor_js/blocks/markdown_block'
|
|
23
24
|
require 'editor_js/blocks/paragraph_block'
|
24
25
|
require 'editor_js/blocks/qiniu_image_block'
|
25
26
|
require 'editor_js/blocks/quote_block'
|
27
|
+
require 'editor_js/blocks/warning_block.rb'
|
26
28
|
require 'editor_js/blocks/table_block'
|
27
29
|
require 'editor_js/blocks/attaches_block'
|
28
30
|
require 'editor_js/document'
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module EditorJs
|
4
4
|
module Blocks
|
5
|
+
# checklist block
|
5
6
|
class ChecklistBlock < Base
|
6
7
|
def schema
|
7
8
|
YAML.safe_load(<<~YAML)
|
@@ -35,8 +36,8 @@ module EditorJs
|
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
|
-
def
|
39
|
-
|
39
|
+
def safe_tags
|
40
|
+
{
|
40
41
|
'b' => nil,
|
41
42
|
'i' => nil,
|
42
43
|
'u' => ['class'],
|
@@ -45,12 +46,14 @@ module EditorJs
|
|
45
46
|
'mark' => ['class'],
|
46
47
|
'code' => ['class']
|
47
48
|
}
|
49
|
+
end
|
48
50
|
|
51
|
+
def sanitize!
|
49
52
|
data['items'].each do |item|
|
50
53
|
item['text'] = Sanitize.fragment(
|
51
54
|
item['text'],
|
52
55
|
elements: safe_tags.keys,
|
53
|
-
attributes: safe_tags.select {|
|
56
|
+
attributes: safe_tags.select { |_k, v| v },
|
54
57
|
remove_contents: true
|
55
58
|
)
|
56
59
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module EditorJs
|
4
4
|
module Blocks
|
5
|
+
# list block
|
5
6
|
class ListBlock < Base
|
6
7
|
def schema
|
7
8
|
YAML.safe_load(<<~YAML)
|
@@ -29,8 +30,8 @@ module EditorJs
|
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
def
|
33
|
-
|
33
|
+
def safe_tags
|
34
|
+
{
|
34
35
|
'b' => nil,
|
35
36
|
'i' => nil,
|
36
37
|
'u' => ['class'],
|
@@ -39,12 +40,14 @@ module EditorJs
|
|
39
40
|
'mark' => ['class'],
|
40
41
|
'code' => ['class']
|
41
42
|
}
|
43
|
+
end
|
42
44
|
|
45
|
+
def sanitize!
|
43
46
|
data['items'] = data['items'].map do |text|
|
44
47
|
Sanitize.fragment(
|
45
48
|
text,
|
46
49
|
elements: safe_tags.keys,
|
47
|
-
attributes: safe_tags.select {|
|
50
|
+
attributes: safe_tags.select { |_k, v| v },
|
48
51
|
remove_contents: true
|
49
52
|
)
|
50
53
|
end
|
@@ -2,22 +2,8 @@
|
|
2
2
|
|
3
3
|
module EditorJs
|
4
4
|
module Blocks
|
5
|
+
# markdown block
|
5
6
|
class MarkdownBlock < Base
|
6
|
-
class HTMLwithCodeRay < Redcarpet::Render::HTML
|
7
|
-
def block_code(code, language)
|
8
|
-
CodeRay.scan(code, language || :text).div(css: :class)
|
9
|
-
end
|
10
|
-
|
11
|
-
def list_item(text, list_type)
|
12
|
-
if text.start_with?("[x]", "[X]")
|
13
|
-
text[0..2] = %(<input type='checkbox' checked='checked' disabled>)
|
14
|
-
elsif text.start_with?("[ ]")
|
15
|
-
text[0..2] = %(<input type='checkbox' disabled>)
|
16
|
-
end
|
17
|
-
%(<li>#{text}</li>)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
7
|
def sanitize!; end
|
22
8
|
|
23
9
|
def schema
|
@@ -30,33 +16,29 @@ module EditorJs
|
|
30
16
|
YAML
|
31
17
|
end
|
32
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')
|
33
32
|
def render(_options = {})
|
34
33
|
content_tag :div, class: css_name do
|
35
34
|
content_text = data['text'] || ''
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
renderer = HTMLwithCodeRay.new(render_options)
|
44
|
-
|
45
|
-
options = {
|
46
|
-
autolink: true,
|
47
|
-
fenced_code_blocks: true,
|
48
|
-
lax_spacing: true,
|
49
|
-
no_intra_emphasis: true,
|
50
|
-
strikethrough: true,
|
51
|
-
tables: true,
|
52
|
-
superscript: true,
|
53
|
-
highlight: true,
|
54
|
-
quote: true,
|
55
|
-
footnotes: true
|
56
|
-
}
|
57
|
-
markdown_to_html = Redcarpet::Markdown.new(renderer, options)
|
58
|
-
|
59
|
-
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
|
60
42
|
end
|
61
43
|
end
|
62
44
|
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module EditorJs
|
4
4
|
module Blocks
|
5
|
+
# paragraph block
|
5
6
|
class ParagraphBlock < Base
|
6
7
|
def schema
|
7
8
|
YAML.safe_load(<<~YAML)
|
@@ -31,8 +32,8 @@ module EditorJs
|
|
31
32
|
content_tag(:div, class: class_name_str) { data['text'].html_safe }
|
32
33
|
end
|
33
34
|
|
34
|
-
def
|
35
|
-
|
35
|
+
def safe_tags
|
36
|
+
{
|
36
37
|
'b' => nil,
|
37
38
|
'i' => nil,
|
38
39
|
'u' => ['class'],
|
@@ -41,11 +42,13 @@ module EditorJs
|
|
41
42
|
'mark' => ['class'],
|
42
43
|
'code' => ['class']
|
43
44
|
}
|
45
|
+
end
|
44
46
|
|
47
|
+
def sanitize!
|
45
48
|
data['text'] = Sanitize.fragment(
|
46
49
|
data['text'],
|
47
50
|
elements: safe_tags.keys,
|
48
|
-
attributes: safe_tags.select {|
|
51
|
+
attributes: safe_tags.select { |_k, v| v },
|
49
52
|
remove_contents: true
|
50
53
|
)
|
51
54
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module EditorJs
|
4
4
|
module Blocks
|
5
|
+
# quote block
|
5
6
|
class QuoteBlock < Base
|
6
7
|
def schema
|
7
8
|
YAML.safe_load(<<~YAML)
|
@@ -28,8 +29,8 @@ module EditorJs
|
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
31
|
-
def
|
32
|
-
|
32
|
+
def safe_tags
|
33
|
+
{
|
33
34
|
'b' => nil,
|
34
35
|
'i' => nil,
|
35
36
|
'u' => ['class'],
|
@@ -39,12 +40,14 @@ module EditorJs
|
|
39
40
|
'code' => ['class'],
|
40
41
|
'br' => nil
|
41
42
|
}
|
43
|
+
end
|
42
44
|
|
43
|
-
|
45
|
+
def sanitize!
|
46
|
+
%w[text caption].each do |key|
|
44
47
|
data[key] = Sanitize.fragment(
|
45
48
|
data[key],
|
46
49
|
elements: safe_tags.keys,
|
47
|
-
attributes: safe_tags.select {|
|
50
|
+
attributes: safe_tags.select { |_k, v| v },
|
48
51
|
remove_contents: false
|
49
52
|
)
|
50
53
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module EditorJs
|
4
4
|
module Blocks
|
5
|
+
# table block
|
5
6
|
class TableBlock < Base
|
6
7
|
def schema
|
7
8
|
YAML.safe_load(<<~YAML)
|
@@ -29,16 +30,35 @@ module EditorJs
|
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
33
|
+
def safe_tags
|
34
|
+
{
|
35
|
+
'b' => nil,
|
36
|
+
'i' => nil,
|
37
|
+
'u' => ['class'],
|
38
|
+
'del' => ['class'],
|
39
|
+
'a' => ['href'],
|
40
|
+
'mark' => ['class'],
|
41
|
+
'code' => ['class'],
|
42
|
+
'br' => nil
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
32
46
|
def sanitize!
|
33
47
|
data['content'] = data['content'].map do |row|
|
34
|
-
|
35
|
-
Sanitize.fragment(
|
48
|
+
(row || []).map do |cell_value|
|
49
|
+
Sanitize.fragment(
|
50
|
+
cell_value,
|
51
|
+
elements: safe_tags.keys,
|
52
|
+
attributes: safe_tags.select { |_k, v| v },
|
53
|
+
remove_contents: false
|
54
|
+
)
|
36
55
|
end
|
37
56
|
end
|
38
57
|
end
|
39
58
|
|
40
59
|
def plain
|
41
|
-
|
60
|
+
str = data['content'].flatten.join(', ')
|
61
|
+
decode_html Sanitize.fragment(str).gsub(/(, )+/, ', ').strip
|
42
62
|
end
|
43
63
|
end
|
44
64
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EditorJs
|
4
|
+
module Blocks
|
5
|
+
# warning block
|
6
|
+
class WarningBlock < Base
|
7
|
+
def schema
|
8
|
+
YAML.safe_load(<<~YAML)
|
9
|
+
type: object
|
10
|
+
additionalProperties: false
|
11
|
+
properties:
|
12
|
+
title:
|
13
|
+
type: string
|
14
|
+
message:
|
15
|
+
type: string
|
16
|
+
YAML
|
17
|
+
end
|
18
|
+
|
19
|
+
def render(_options = {})
|
20
|
+
title = data['title'].html_safe
|
21
|
+
message = data['message'].html_safe
|
22
|
+
|
23
|
+
content_tag :div, class: css_name do
|
24
|
+
html_str = content_tag :div, title, class: "#{css_name}__title"
|
25
|
+
html_str << content_tag(:div, message, class: "#{css_name}__message")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def safe_tags
|
30
|
+
{
|
31
|
+
'b' => nil,
|
32
|
+
'i' => nil,
|
33
|
+
'u' => ['class'],
|
34
|
+
'del' => ['class'],
|
35
|
+
'a' => ['href'],
|
36
|
+
'mark' => ['class'],
|
37
|
+
'code' => ['class']
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def sanitize!
|
42
|
+
%w[title message].each do |key|
|
43
|
+
data[key] = Sanitize.fragment(
|
44
|
+
data[key],
|
45
|
+
elements: safe_tags.keys,
|
46
|
+
attributes: safe_tags.select { |_k, v| v },
|
47
|
+
remove_contents: false
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def plain
|
53
|
+
string = [
|
54
|
+
Sanitize.fragment(data['title']).strip,
|
55
|
+
Sanitize.fragment(data['message']).strip
|
56
|
+
].join(', ')
|
57
|
+
decode_html(string)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/editor_js/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xiaohui
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-12 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:
|
42
|
+
name: commonmarker
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
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:
|
54
|
+
version: 0.21.2
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: htmlentities
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
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: '
|
71
|
+
version: '4.3'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 4.3.4
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
76
|
+
name: json-schema
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
72
78
|
requirements:
|
73
79
|
- - "~>"
|
74
80
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
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: '
|
86
|
-
- - ">="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: 4.3.4
|
88
|
+
version: '2'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
90
|
+
name: rouge
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: '3.
|
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.
|
102
|
+
version: '3.26'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
|
-
name:
|
104
|
+
name: sanitize
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
107
|
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: '
|
110
|
-
- - ">="
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
version: 1.1.2
|
109
|
+
version: '6.0'
|
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: '
|
120
|
-
- - ">="
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
version: 1.1.2
|
116
|
+
version: '6.0'
|
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
|
@@ -196,6 +192,7 @@ files:
|
|
196
192
|
- lib/editor_js/blocks/qiniu_image_block.rb
|
197
193
|
- lib/editor_js/blocks/quote_block.rb
|
198
194
|
- lib/editor_js/blocks/table_block.rb
|
195
|
+
- lib/editor_js/blocks/warning_block.rb
|
199
196
|
- lib/editor_js/document.rb
|
200
197
|
- lib/editor_js/version.rb
|
201
198
|
homepage: https://github.com/xiaohui-zhangxh/editor_js
|
@@ -205,7 +202,7 @@ metadata:
|
|
205
202
|
homepage_uri: https://github.com/xiaohui-zhangxh/editor_js
|
206
203
|
source_code_uri: https://github.com/xiaohui-zhangxh/editor_js
|
207
204
|
changelog_uri: https://github.com/xiaohui-zhangxh/editor_js
|
208
|
-
post_install_message:
|
205
|
+
post_install_message:
|
209
206
|
rdoc_options: []
|
210
207
|
require_paths:
|
211
208
|
- lib
|
@@ -220,8 +217,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
217
|
- !ruby/object:Gem::Version
|
221
218
|
version: '0'
|
222
219
|
requirements: []
|
223
|
-
rubygems_version: 3.
|
224
|
-
signing_key:
|
220
|
+
rubygems_version: 3.1.6
|
221
|
+
signing_key:
|
225
222
|
specification_version: 4
|
226
223
|
summary: Ruby gem for editorjs.io text editor
|
227
224
|
test_files: []
|