draftjs_html 0.26.0 → 0.28.0

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: 9fe4601ed10ebae8924fe906ffad4cd56bebf7867ec80182876ad0a1b5a3b739
4
- data.tar.gz: 5d14c45c7192c936fbbe524a72c4886acddaf20f1f2dff5ccf9c1ce3d8de8a5f
3
+ metadata.gz: ee7df9bd0f6a54994b17925c487f2c824ec538e773abe2c56b5591e5cd846573
4
+ data.tar.gz: c874e8b188f77d2ffd7ade661ff5e61cea5c136b0d89e3a9bf022a5e87de142f
5
5
  SHA512:
6
- metadata.gz: 38f78c86afbac0244a8eb967be90c6b647001e6a3bbbe3a6648190a45ac9cbecc2359c45f1fee5f995ed9584d037b2c337b8e267dece3c38e15a16a4dde8b775
7
- data.tar.gz: 249423024673740842728d7b5cb8ca4ef1aa9bec1ee521be4402e21d5d89afa7f36563232de9c6af62831ae9cac3768c654537d75a8dbb44e25735f4d2dc0ac1
6
+ metadata.gz: 4f4dc0f13111d6a0424d24620810bb5ac928bade2a1ba29fee46baa182e91a67430909920b3c9be69f4836299fbc44953f4db8c20a4948431e33bfc496def6a0
7
+ data.tar.gz: 852986e0ce26c74d377bd8c202de3a898510b5ef5b20f594b65e035c3b25258a11375a4aed562aa62cbfcdd42388125316d9bef82cbf8ff670ba442a766ff926
@@ -1,6 +1,7 @@
1
1
  module DraftjsHtml
2
2
  module HtmlDefaults
3
3
  BLOCK_TYPE_TO_HTML = {
4
+ 'section' => 'p',
4
5
  'article' => 'p',
5
6
  'paragraph' => 'p',
6
7
  'unstyled' => 'p',
@@ -19,7 +19,7 @@ module DraftjsHtml
19
19
  return unless nesting_root_changed?(block) || depth_changed?(block)
20
20
 
21
21
  if deepening?(block)
22
- deepen(block)
22
+ deepen(block, desired_depth_change: block.depth - @current_depth)
23
23
  elsif rising?(block) && still_nested?(block)
24
24
  rise(times: @current_depth - block.depth)
25
25
  elsif rising?(block)
@@ -36,11 +36,17 @@ module DraftjsHtml
36
36
 
37
37
  private
38
38
 
39
- def deepen(block)
40
- tagname = BLOCK_TYPE_TO_HTML_WRAPPER[block.type]
41
- @previous_parents << @body.parent
42
- @nesting_roots << tagname
43
- @body.parent = @body.parent.last_element_child
39
+ def deepen(block, desired_depth_change: 0)
40
+ if inside_valid_nesting_root?
41
+ set_previous_li_as_parent(block)
42
+ else
43
+ create_valid_nesting_root(block)
44
+ end
45
+
46
+ (desired_depth_change - 1).times do
47
+ create_valid_nesting_root(block)
48
+ end
49
+
44
50
  push_parent(block)
45
51
  end
46
52
 
@@ -91,5 +97,27 @@ module DraftjsHtml
91
97
  def deepening?(block)
92
98
  @current_depth < block.depth
93
99
  end
100
+
101
+ def create_valid_nesting_root(block)
102
+ parent_tagname = BLOCK_TYPE_TO_HTML_WRAPPER[block.type]
103
+ node = create_child(parent_tagname)
104
+ @previous_parents << node
105
+ @nesting_roots << parent_tagname
106
+ @body.parent = node
107
+
108
+ list_item = create_child('li')
109
+ @body.parent = list_item
110
+ end
111
+
112
+ def set_previous_li_as_parent(block)
113
+ tagname = BLOCK_TYPE_TO_HTML_WRAPPER[block.type]
114
+ @previous_parents << @body.parent
115
+ @nesting_roots << tagname
116
+ @body.parent = @body.parent.last_element_child
117
+ end
118
+
119
+ def inside_valid_nesting_root?
120
+ BLOCK_TYPE_TO_HTML_WRAPPER.values.include?(@body.parent.name)
121
+ end
94
122
  end
95
123
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DraftjsHtml
4
- VERSION = "0.26.0"
4
+ VERSION = "0.28.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: draftjs_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.0
4
+ version: 0.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-06 00:00:00.000000000 Z
11
+ date: 2023-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri