draftjs_html 0.5.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9194cbbbe5e94b79dd386efd86e23774128659b74fb40c98ddf43bc9b62fd9a9
4
- data.tar.gz: 121e6900da99a52b8a5e0cf5b1cae7206492e979939b214d9ef3a112ebdc471d
3
+ metadata.gz: 0e6d6f1d7f1c978841fe029f93f5db47688459ec70f2b33de5ed7c9cfa6d2758
4
+ data.tar.gz: 40ee34b8ba65efaf7c3c627046c06bd1e03c32547a17b111cfc661b7bd7a0a7f
5
5
  SHA512:
6
- metadata.gz: e574a85e36eb144f9f5b4e56a766cb3c83385fad293c311627d1ae5974408c8bd5ce39dc6a2081e9d7b9e695ce08dea54ef2050768c1f5660ef478d992e10671
7
- data.tar.gz: 0dc0ce686a9d476a93c24e392d02ee7180b4fd556636cce72695562936acb2e5c3dec581c3151e9d8fd3ed32b9aa026d644cb524c2579925479fa8d4f8927e1e
6
+ metadata.gz: 4427355fcb9c1578edc43d67c7fd04ba9c64001dae800996c7124938c0fe2c28d5e4da29e35fda0f2b4659656f829c62dd16b9e482a0e4b6fc780cffe8a1223c
7
+ data.tar.gz: 1277ff4825ce7a8bb972c4c0cbca2b3b0f440eceee3e6c00346b78b99d9bc900f8497f4a562b56d2cc8427b545418f578c64358d90618dcb7ce39fff5e196b43
@@ -3,12 +3,34 @@ module DraftjsHtml
3
3
  def to_nokogiri(_document)
4
4
  node
5
5
  end
6
+
7
+ def wrap(tagname, attrs = {})
8
+ Node.new(tagname, attrs, self)
9
+ end
10
+
11
+ def to_s
12
+ node.to_s
13
+ end
6
14
  end
7
15
 
8
16
  StringNode = Struct.new(:raw) do
9
17
  def to_nokogiri(document)
10
- raw
11
- Nokogiri::XML::Text.new(raw, document)
18
+ lines = raw.lines
19
+ text_nodes = lines.flat_map.with_index do |text, i|
20
+ nodes = [Nokogiri::XML::Text.new(text.chomp, document)]
21
+ nodes << Nokogiri::XML::Node.new('br', document) if i < lines.size - 1
22
+ nodes
23
+ end
24
+
25
+ Nokogiri::XML::NodeSet.new(document, text_nodes)
26
+ end
27
+
28
+ def wrap(tagname, attrs = {})
29
+ Node.new(tagname, attrs, self)
30
+ end
31
+
32
+ def to_s
33
+ raw.to_s
12
34
  end
13
35
  end
14
36
 
@@ -24,9 +46,17 @@ module DraftjsHtml
24
46
 
25
47
  def to_nokogiri(document)
26
48
  Nokogiri::XML::Node.new(element_name, document).tap do |node|
27
- node.content = content
49
+ node << content.to_nokogiri(document) if content
28
50
  (attributes || {}).each { |k, v| node[k] = v }
29
51
  end
30
52
  end
53
+
54
+ def wrap(tagname, attrs = {})
55
+ Node.new(tagname, attrs, self)
56
+ end
57
+
58
+ def to_s
59
+ content.to_s
60
+ end
31
61
  end
32
62
  end
@@ -70,7 +70,7 @@ module DraftjsHtml
70
70
  block.each_range do |char_range|
71
71
  content = try_apply_entity_to(draftjs, char_range)
72
72
 
73
- apply_styles_to(block_body, char_range.style_names, content)
73
+ apply_styles_to(block_body, char_range.style_names, Node.of(content))
74
74
  end
75
75
  end
76
76
  end
@@ -124,7 +124,7 @@ module DraftjsHtml
124
124
  content = char_range.text
125
125
  if entity
126
126
  style_fn = (@options[:entity_style_mappings][entity.type] || DEFAULT_ENTITY_STYLE_FN)
127
- content = style_fn.call(entity, content, @document.parent)
127
+ content = style_fn.call(entity, Node.of(content), @document.parent)
128
128
  end
129
129
 
130
130
  content
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DraftjsHtml
4
- VERSION = "0.5.1"
4
+ VERSION = "0.7.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.5.1
4
+ version: 0.7.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: 2022-10-06 00:00:00.000000000 Z
11
+ date: 2022-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri