editor_js 0.2.5 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +18 -18
- data/editor_js.gemspec +1 -1
- data/lib/editor_js.rb +2 -0
- data/lib/editor_js/blocks/attaches_block.rb +112 -0
- data/lib/editor_js/blocks/checklist_block.rb +20 -2
- 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 +16 -1
- data/lib/editor_js/blocks/image_block.rb +1 -0
- data/lib/editor_js/blocks/list_block.rb +8 -3
- data/lib/editor_js/blocks/markdown_block.rb +1 -0
- data/lib/editor_js/blocks/paragraph_block.rb +23 -4
- data/lib/editor_js/blocks/qiniu_image_block.rb +1 -0
- data/lib/editor_js/blocks/quote_block.rb +9 -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 +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a00ab346b57a44f9fd23bcdca062aa86f0cee25326a5db5e810d193129498a7
|
4
|
+
data.tar.gz: 3e96bc0177d267807ad49915cd2eebb312bb29789931da69ed71cdb58f48dedc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e65a5f80e1e92a752d39c01a1b72d869d597e12aa541f7790c08d84f3ba84d543f39d74a5758d3a2d54eef8fde9fb32bd8ee90b4a0e5949f044946e27945841a
|
7
|
+
data.tar.gz: af6f3ec9825b66dcadabfb05872de9dcc366be87382997dc468dacdf0da9132e4ca02028ffc307c841ae124a948d72ad42546103db7682caee0c5981ea6e6c21
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
editor_js (0.
|
4
|
+
editor_js (0.3.5)
|
5
5
|
actionview (>= 4)
|
6
6
|
activesupport (>= 4)
|
7
7
|
coderay (~> 1.1, >= 1.1.2)
|
@@ -13,42 +13,42 @@ PATH
|
|
13
13
|
GEM
|
14
14
|
remote: https://rubygems.org/
|
15
15
|
specs:
|
16
|
-
actionview (6.0.2
|
17
|
-
activesupport (= 6.0.2
|
16
|
+
actionview (6.0.3.2)
|
17
|
+
activesupport (= 6.0.3.2)
|
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.2
|
22
|
+
activesupport (6.0.3.2)
|
23
23
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
24
24
|
i18n (>= 0.7, < 2)
|
25
25
|
minitest (~> 5.1)
|
26
26
|
tzinfo (~> 1.1)
|
27
|
-
zeitwerk (~> 2.2)
|
27
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
28
28
|
addressable (2.7.0)
|
29
29
|
public_suffix (>= 2.0.2, < 5.0)
|
30
30
|
ast (2.4.0)
|
31
31
|
builder (3.2.4)
|
32
32
|
coderay (1.1.2)
|
33
|
-
concurrent-ruby (1.1.
|
34
|
-
crass (1.0.
|
33
|
+
concurrent-ruby (1.1.6)
|
34
|
+
crass (1.0.6)
|
35
35
|
diff-lcs (1.3)
|
36
36
|
docile (1.3.2)
|
37
37
|
erubi (1.9.0)
|
38
38
|
htmlentities (4.3.4)
|
39
|
-
i18n (1.
|
39
|
+
i18n (1.8.3)
|
40
40
|
concurrent-ruby (~> 1.0)
|
41
41
|
jaro_winkler (1.5.4)
|
42
42
|
json (2.3.0)
|
43
43
|
json-schema (2.8.1)
|
44
44
|
addressable (>= 2.4)
|
45
|
-
loofah (2.
|
45
|
+
loofah (2.6.0)
|
46
46
|
crass (~> 1.0.2)
|
47
47
|
nokogiri (>= 1.5.9)
|
48
48
|
method_source (0.9.2)
|
49
49
|
mini_portile2 (2.4.0)
|
50
|
-
minitest (5.
|
51
|
-
nokogiri (1.10.
|
50
|
+
minitest (5.14.1)
|
51
|
+
nokogiri (1.10.10)
|
52
52
|
mini_portile2 (~> 2.4.0)
|
53
53
|
nokogumbo (2.0.2)
|
54
54
|
nokogiri (~> 1.8, >= 1.8.4)
|
@@ -58,14 +58,14 @@ GEM
|
|
58
58
|
pry (0.12.2)
|
59
59
|
coderay (~> 1.1.0)
|
60
60
|
method_source (~> 0.9.0)
|
61
|
-
public_suffix (4.0.
|
61
|
+
public_suffix (4.0.5)
|
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 (
|
68
|
+
rake (13.0.1)
|
69
69
|
redcarpet (3.5.0)
|
70
70
|
rspec (3.9.0)
|
71
71
|
rspec-core (~> 3.9.0)
|
@@ -88,7 +88,7 @@ GEM
|
|
88
88
|
ruby-progressbar (~> 1.7)
|
89
89
|
unicode-display_width (>= 1.4.0, < 1.7)
|
90
90
|
ruby-progressbar (1.10.1)
|
91
|
-
sanitize (5.1
|
91
|
+
sanitize (5.2.1)
|
92
92
|
crass (~> 1.0.2)
|
93
93
|
nokogiri (>= 1.8.0)
|
94
94
|
nokogumbo (~> 2.0)
|
@@ -98,10 +98,10 @@ GEM
|
|
98
98
|
simplecov-html (~> 0.10.0)
|
99
99
|
simplecov-html (0.10.2)
|
100
100
|
thread_safe (0.3.6)
|
101
|
-
tzinfo (1.2.
|
101
|
+
tzinfo (1.2.7)
|
102
102
|
thread_safe (~> 0.1)
|
103
103
|
unicode-display_width (1.6.0)
|
104
|
-
zeitwerk (2.
|
104
|
+
zeitwerk (2.3.1)
|
105
105
|
|
106
106
|
PLATFORMS
|
107
107
|
ruby
|
@@ -110,10 +110,10 @@ DEPENDENCIES
|
|
110
110
|
bundler (~> 2.0)
|
111
111
|
editor_js!
|
112
112
|
pry (~> 0.12.2)
|
113
|
-
rake (~>
|
113
|
+
rake (~> 13.0)
|
114
114
|
rspec (~> 3.0)
|
115
115
|
rubocop (~> 0.77.0)
|
116
116
|
simplecov (~> 0.17.1)
|
117
117
|
|
118
118
|
BUNDLED WITH
|
119
|
-
2.
|
119
|
+
2.1.4
|
data/editor_js.gemspec
CHANGED
@@ -33,6 +33,6 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_dependency 'redcarpet', '~> 3.5'
|
34
34
|
spec.add_dependency 'coderay', '~> 1.1', '>= 1.1.2'
|
35
35
|
spec.add_development_dependency "bundler", "~> 2.0"
|
36
|
-
spec.add_development_dependency "rake", "~>
|
36
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
37
37
|
spec.add_development_dependency "rspec", "~> 3.0"
|
38
38
|
end
|
data/lib/editor_js.rb
CHANGED
@@ -23,7 +23,9 @@ require 'editor_js/blocks/markdown_block'
|
|
23
23
|
require 'editor_js/blocks/paragraph_block'
|
24
24
|
require 'editor_js/blocks/qiniu_image_block'
|
25
25
|
require 'editor_js/blocks/quote_block'
|
26
|
+
require 'editor_js/blocks/warning_block.rb'
|
26
27
|
require 'editor_js/blocks/table_block'
|
28
|
+
require 'editor_js/blocks/attaches_block'
|
27
29
|
require 'editor_js/document'
|
28
30
|
|
29
31
|
module EditorJs
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EditorJs
|
4
|
+
module Blocks
|
5
|
+
# attaches block
|
6
|
+
class AttachesBlock < Base
|
7
|
+
include ActiveSupport::NumberHelper
|
8
|
+
|
9
|
+
def schema
|
10
|
+
YAML.safe_load(<<~YAML)
|
11
|
+
type: object
|
12
|
+
additionalProperties: false
|
13
|
+
properties:
|
14
|
+
file:
|
15
|
+
type: object
|
16
|
+
additionalProperties: false
|
17
|
+
properties:
|
18
|
+
url:
|
19
|
+
type: string
|
20
|
+
name:
|
21
|
+
type: string
|
22
|
+
type:
|
23
|
+
type: string
|
24
|
+
size:
|
25
|
+
type: number
|
26
|
+
title:
|
27
|
+
type: string
|
28
|
+
required:
|
29
|
+
- file
|
30
|
+
YAML
|
31
|
+
end
|
32
|
+
|
33
|
+
EXTENSIONS = {
|
34
|
+
'doc' => '#3e74da',
|
35
|
+
'docx' => '#3e74da',
|
36
|
+
'odt' => '#3e74da',
|
37
|
+
'pdf' => '#d47373',
|
38
|
+
'rtf' => '#656ecd',
|
39
|
+
'tex' => '#5a5a5b',
|
40
|
+
'txt' => '#5a5a5b',
|
41
|
+
'pptx' => '#e07066',
|
42
|
+
'ppt' => '#e07066',
|
43
|
+
'mp3' => '#eab456',
|
44
|
+
'mp4' => '#f676a6',
|
45
|
+
'xls' => '#3f9e64',
|
46
|
+
'html' => '#2988f0',
|
47
|
+
'htm' => '#2988f0',
|
48
|
+
'png' => '#f676a6',
|
49
|
+
'jpg' => '#f67676',
|
50
|
+
'jpeg' => '#f67676',
|
51
|
+
'gif' => '#f6af76',
|
52
|
+
'zip' => '#4f566f',
|
53
|
+
'rar' => '#4f566f',
|
54
|
+
'exe' => '#e26f6f',
|
55
|
+
'svg' => '#bf5252',
|
56
|
+
'key' => '#e07066',
|
57
|
+
'sketch' => '#df821c',
|
58
|
+
'ai' => '#df821c',
|
59
|
+
'psd' => '#388ae5',
|
60
|
+
'dmg' => '#e26f6f',
|
61
|
+
'json' => '#2988f0',
|
62
|
+
'csv' => '#3f9e64'
|
63
|
+
}
|
64
|
+
|
65
|
+
ICONS = {
|
66
|
+
file_icon: '<svg xmlns="http://www.w3.org/2000/svg" width="32" height="40"><path d="M17 0l15 14V3v34a3 3 0 0 1-3 3H3a3 3 0 0 1-3-3V3a3 3 0 0 1 3-3h20-6zm0 2H3a1 1 0 0 0-1 1v34a1 1 0 0 0 1 1h26a1 1 0 0 0 1-1V14H17V2zm2 10h7.926L19 4.602V12z"></path></svg>',
|
67
|
+
custom_file_icon: '<svg xmlns="http://www.w3.org/2000/svg" width="32" height="40"><g fill="#A8ACB8" fill-rule="evenodd"><path fill-rule="nonzero" d="M17 0l15 14V3v34a3 3 0 0 1-3 3H3a3 3 0 0 1-3-3V3a3 3 0 0 1 3-3h20-6zm0 2H3a1 1 0 0 0-1 1v34a1 1 0 0 0 1 1h26a1 1 0 0 0 1-1V14H17V2zm2 10h7.926L19 4.602V12z"></path><path d="M7 22h18v2H7zm0 4h18v2H7zm0 4h18v2H7z"></path></g></svg>',
|
68
|
+
download_icon: '<svg xmlns="http://www.w3.org/2000/svg" width="17pt" height="17pt" viewBox="0 0 17 17"><path d="M9.457 8.945V2.848A.959.959 0 0 0 8.5 1.89a.959.959 0 0 0-.957.957v6.097L4.488 5.891a.952.952 0 0 0-1.351 0 .952.952 0 0 0 0 1.351l4.687 4.688a.955.955 0 0 0 1.352 0l4.687-4.688a.952.952 0 0 0 0-1.351.952.952 0 0 0-1.351 0zM3.59 14.937h9.82a.953.953 0 0 0 .953-.957.952.952 0 0 0-.953-.953H3.59a.952.952 0 0 0-.953.953c0 .532.425.957.953.957zm0 0" fill-rule="evenodd"></path></svg>'
|
69
|
+
}
|
70
|
+
|
71
|
+
def render(_options = {})
|
72
|
+
file_info = data['file']
|
73
|
+
title = data['title']
|
74
|
+
extension = file_info['name']&.split('.')&.last
|
75
|
+
extension = '' unless EXTENSIONS.key?(extension)
|
76
|
+
|
77
|
+
content_tag :div, class: css_name do
|
78
|
+
html_str = content_tag :div, class: "#{css_name}__file-icon", data: {extension: extension}, style: "color: #{EXTENSIONS[extension]};" do
|
79
|
+
(EXTENSIONS[extension] ? ICONS[:file_icon] : ICONS[:custom_file_icon]).html_safe
|
80
|
+
end
|
81
|
+
|
82
|
+
html_str += content_tag :div, class: "#{css_name}__file-info" do
|
83
|
+
[
|
84
|
+
content_tag(:div, title, class: "#{css_name}__title"),
|
85
|
+
content_tag(:div, number_to_human_size(file_info['size']), class: "#{css_name}__size")
|
86
|
+
].join().html_safe
|
87
|
+
end
|
88
|
+
|
89
|
+
html_str += content_tag :a, class: "#{css_name}__download-button", href: file_info['url'], target: '_blank', rel: 'nofollow noindex noreferrer' do
|
90
|
+
ICONS[:download_icon].html_safe
|
91
|
+
end
|
92
|
+
html_str.html_safe
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def sanitize!
|
97
|
+
data['title'] = Sanitize.fragment(data['title'], remove_contents: true).strip
|
98
|
+
file_info = data['file'] || {}
|
99
|
+
file_info.each do |key, val|
|
100
|
+
break if key == 'size'
|
101
|
+
|
102
|
+
file_info[key] = Sanitize.fragment(val, remove_contents: true).strip
|
103
|
+
end
|
104
|
+
data['file'] = file_info
|
105
|
+
end
|
106
|
+
|
107
|
+
def plain
|
108
|
+
decode_html data['title'].strip
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -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)
|
@@ -28,16 +29,33 @@ module EditorJs
|
|
28
29
|
data['items'].map do |item|
|
29
30
|
content_tag(:div, class: css_name('__warrper')) do
|
30
31
|
html_str = content_tag(:input, nil, type: 'checkbox', disabled: true, checked: item['checked'])
|
31
|
-
html_str += content_tag(:label, item['text'])
|
32
|
+
html_str += content_tag(:label, item['text'].html_safe)
|
32
33
|
html_str.html_safe
|
33
34
|
end.html_safe
|
34
35
|
end.join.html_safe
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
39
|
+
def safe_tags
|
40
|
+
{
|
41
|
+
'b' => nil,
|
42
|
+
'i' => nil,
|
43
|
+
'u' => ['class'],
|
44
|
+
'del' => ['class'],
|
45
|
+
'a' => ['href'],
|
46
|
+
'mark' => ['class'],
|
47
|
+
'code' => ['class']
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
38
51
|
def sanitize!
|
39
52
|
data['items'].each do |item|
|
40
|
-
item['text'] = Sanitize.fragment(
|
53
|
+
item['text'] = Sanitize.fragment(
|
54
|
+
item['text'],
|
55
|
+
elements: safe_tags.keys,
|
56
|
+
attributes: safe_tags.select { |_k, v| v },
|
57
|
+
remove_contents: true
|
58
|
+
)
|
41
59
|
end
|
42
60
|
end
|
43
61
|
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module EditorJs
|
4
4
|
module Blocks
|
5
|
+
# header_block
|
5
6
|
class HeaderBlock < Base
|
6
7
|
def schema
|
7
8
|
YAML.safe_load(<<~YAML)
|
@@ -13,6 +14,12 @@ module EditorJs
|
|
13
14
|
level:
|
14
15
|
type: number
|
15
16
|
enum: [1,2,3,4,5,6]
|
17
|
+
alignment:
|
18
|
+
type: string
|
19
|
+
enum:
|
20
|
+
- align-left
|
21
|
+
- align-center
|
22
|
+
- align-right
|
16
23
|
required:
|
17
24
|
- text
|
18
25
|
- level
|
@@ -20,7 +27,15 @@ module EditorJs
|
|
20
27
|
end
|
21
28
|
|
22
29
|
def render(_options = {})
|
23
|
-
|
30
|
+
alignment = data['alignment']
|
31
|
+
class_name_str = css_name
|
32
|
+
if alignment.present?
|
33
|
+
class_name_str = [
|
34
|
+
class_name_str,
|
35
|
+
css_name("__#{alignment}")
|
36
|
+
].join(' ')
|
37
|
+
end
|
38
|
+
content_tag(:"h#{data['level']}", data['text'].html_safe, class: class_name_str)
|
24
39
|
end
|
25
40
|
|
26
41
|
def sanitize!
|
@@ -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,20 +30,24 @@ 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,
|
37
|
+
'u' => ['class'],
|
38
|
+
'del' => ['class'],
|
36
39
|
'a' => ['href'],
|
37
40
|
'mark' => ['class'],
|
38
41
|
'code' => ['class']
|
39
42
|
}
|
43
|
+
end
|
40
44
|
|
45
|
+
def sanitize!
|
41
46
|
data['items'] = data['items'].map do |text|
|
42
47
|
Sanitize.fragment(
|
43
48
|
text,
|
44
49
|
elements: safe_tags.keys,
|
45
|
-
attributes: safe_tags.select {|
|
50
|
+
attributes: safe_tags.select { |_k, v| v },
|
46
51
|
remove_contents: true
|
47
52
|
)
|
48
53
|
end
|
@@ -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)
|
@@ -10,26 +11,44 @@ module EditorJs
|
|
10
11
|
properties:
|
11
12
|
text:
|
12
13
|
type: string
|
14
|
+
alignment:
|
15
|
+
type: string
|
16
|
+
enum:
|
17
|
+
- align-left
|
18
|
+
- align-center
|
19
|
+
- align-right
|
13
20
|
YAML
|
14
21
|
end
|
15
22
|
|
16
23
|
def render(_options = {})
|
17
|
-
|
24
|
+
alignment = data['alignment']
|
25
|
+
class_name_str = css_name
|
26
|
+
if alignment.present?
|
27
|
+
class_name_str = [
|
28
|
+
class_name_str,
|
29
|
+
css_name("__#{alignment}")
|
30
|
+
].join(' ')
|
31
|
+
end
|
32
|
+
content_tag(:div, class: class_name_str) { data['text'].html_safe }
|
18
33
|
end
|
19
34
|
|
20
|
-
def
|
21
|
-
|
35
|
+
def safe_tags
|
36
|
+
{
|
22
37
|
'b' => nil,
|
23
38
|
'i' => nil,
|
39
|
+
'u' => ['class'],
|
40
|
+
'del' => ['class'],
|
24
41
|
'a' => ['href'],
|
25
42
|
'mark' => ['class'],
|
26
43
|
'code' => ['class']
|
27
44
|
}
|
45
|
+
end
|
28
46
|
|
47
|
+
def sanitize!
|
29
48
|
data['text'] = Sanitize.fragment(
|
30
49
|
data['text'],
|
31
50
|
elements: safe_tags.keys,
|
32
|
-
attributes: safe_tags.select {|
|
51
|
+
attributes: safe_tags.select { |_k, v| v },
|
33
52
|
remove_contents: true
|
34
53
|
)
|
35
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,21 +29,25 @@ 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,
|
36
|
+
'u' => ['class'],
|
37
|
+
'del' => ['class'],
|
35
38
|
'a' => ['href'],
|
36
39
|
'mark' => ['class'],
|
37
40
|
'code' => ['class'],
|
38
41
|
'br' => nil
|
39
42
|
}
|
43
|
+
end
|
40
44
|
|
41
|
-
|
45
|
+
def sanitize!
|
46
|
+
%w[text caption].each do |key|
|
42
47
|
data[key] = Sanitize.fragment(
|
43
48
|
data[key],
|
44
49
|
elements: safe_tags.keys,
|
45
|
-
attributes: safe_tags.select {|
|
50
|
+
attributes: safe_tags.select { |_k, v| v },
|
46
51
|
remove_contents: false
|
47
52
|
)
|
48
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.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xiaohui
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -140,14 +140,14 @@ dependencies:
|
|
140
140
|
requirements:
|
141
141
|
- - "~>"
|
142
142
|
- !ruby/object:Gem::Version
|
143
|
-
version: '
|
143
|
+
version: '13.0'
|
144
144
|
type: :development
|
145
145
|
prerelease: false
|
146
146
|
version_requirements: !ruby/object:Gem::Requirement
|
147
147
|
requirements:
|
148
148
|
- - "~>"
|
149
149
|
- !ruby/object:Gem::Version
|
150
|
-
version: '
|
150
|
+
version: '13.0'
|
151
151
|
- !ruby/object:Gem::Dependency
|
152
152
|
name: rspec
|
153
153
|
requirement: !ruby/object:Gem::Requirement
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- bin/setup
|
183
183
|
- editor_js.gemspec
|
184
184
|
- lib/editor_js.rb
|
185
|
+
- lib/editor_js/blocks/attaches_block.rb
|
185
186
|
- lib/editor_js/blocks/base.rb
|
186
187
|
- lib/editor_js/blocks/checklist_block.rb
|
187
188
|
- lib/editor_js/blocks/code_block.rb
|
@@ -195,6 +196,7 @@ files:
|
|
195
196
|
- lib/editor_js/blocks/qiniu_image_block.rb
|
196
197
|
- lib/editor_js/blocks/quote_block.rb
|
197
198
|
- lib/editor_js/blocks/table_block.rb
|
199
|
+
- lib/editor_js/blocks/warning_block.rb
|
198
200
|
- lib/editor_js/document.rb
|
199
201
|
- lib/editor_js/version.rb
|
200
202
|
homepage: https://github.com/xiaohui-zhangxh/editor_js
|
@@ -204,7 +206,7 @@ metadata:
|
|
204
206
|
homepage_uri: https://github.com/xiaohui-zhangxh/editor_js
|
205
207
|
source_code_uri: https://github.com/xiaohui-zhangxh/editor_js
|
206
208
|
changelog_uri: https://github.com/xiaohui-zhangxh/editor_js
|
207
|
-
post_install_message:
|
209
|
+
post_install_message:
|
208
210
|
rdoc_options: []
|
209
211
|
require_paths:
|
210
212
|
- lib
|
@@ -219,8 +221,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
221
|
- !ruby/object:Gem::Version
|
220
222
|
version: '0'
|
221
223
|
requirements: []
|
222
|
-
rubygems_version: 3.0.
|
223
|
-
signing_key:
|
224
|
+
rubygems_version: 3.0.8
|
225
|
+
signing_key:
|
224
226
|
specification_version: 4
|
225
227
|
summary: Ruby gem for editorjs.io text editor
|
226
228
|
test_files: []
|