draftjs_html 0.22.0 → 0.24.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: 84ac3de7f21860685dbf39a24fb921227a1ccce6d97940acd279976daab15970
4
- data.tar.gz: 2d3511eef3134a6cc01cd3da0147b3c347209c6c90ef4f5aaea90c681af979b1
3
+ metadata.gz: 7c2703fb050f796abd4f8af851d16b654a2ab84f03e5f8865c92b373b2acfefa
4
+ data.tar.gz: eced6f85cfefd34f4c50c7fc383526675f26dd7c212a4f7de145721d254b1a28
5
5
  SHA512:
6
- metadata.gz: 2775eac524063149973d4908f9f30f5e9a4d6b734f35e44b459454a95cc6a415a25a1b36daf07af3b34b1bf08b2b96c2980e6be12a9b21ed23c162100688ad03
7
- data.tar.gz: dd0c42f5271934a1a17452159e7dbad8b51bd4ad0637a9b87cf4c77b43c6ea690bdda838830d92b1fcd929e985d88958fa5bd5326af89dc3e9db76e7e84a5fe2
6
+ metadata.gz: 432d7b8900153f89f8ba506ded86208fe71a4b6b832911693059e0f57cb31b93412ef8fa5a40a8f7d857b370b65e8a523f29d0029dfa2ee8f917ebae2235827e
7
+ data.tar.gz: 69878d4330ef0d4947f1d95ed165720c0a59b8c0d54793d2e28aad8f5fea40754f95afacc1fc1a29c5b5b9f03e02399d9502924c7c580e7bc953b674f6292644
data/README.md CHANGED
@@ -229,6 +229,15 @@ The callable should return a Hash with symbol keys. The supported values are:
229
229
  - `data` (optional, default `{}`)
230
230
  - an arbitrary data-bag (Hash) of entity data
231
231
 
232
+ #### `:is_semantic_markup:`
233
+
234
+ Defaults to `true`.
235
+
236
+ By setting to `false`, the user is stating they want to treat `div` tags as semantic,
237
+ block-level tags. In some markup (emails, for example), there are no semantic tags
238
+ (read, no `p` tags), so the only indications of whitespace and structure come from
239
+ `div` tags. This flag will flush content wrapped in a `div` as a DraftJS block.
240
+
232
241
  ## Development
233
242
 
234
243
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
@@ -131,22 +131,6 @@ module DraftjsHtml
131
131
  end
132
132
  end
133
133
  end
134
-
135
- private
136
-
137
- def find_overlapping_styles(descriptors)
138
- descriptors.select do |candidate_a|
139
- candidate_range = candidate_a[:start]..candidate_a[:finish]
140
- (descriptors - [candidate_a]).any? do |other|
141
- other_range = other[:start]..other[:finish]
142
- range_overlaps?(candidate_range, other_range)
143
- end
144
- end
145
- end
146
-
147
- def range_overlaps?(candidate_range, other_range)
148
- other_range.begin == candidate_range.begin || candidate_range.cover?(other_range.begin) || other_range.cover?(candidate_range.begin)
149
- end
150
134
  end
151
135
  end
152
136
  end
@@ -1,15 +1,16 @@
1
1
  module DraftjsHtml
2
2
  class FromHtml < Nokogiri::XML::SAX::Document
3
3
  class DepthStack
4
- def initialize
4
+ def initialize(is_semantic_markup: true)
5
5
  @stack = []
6
6
  @nodes = []
7
7
  @list_depth = -1
8
8
  @active_styles = []
9
+ @is_semantic_markup = is_semantic_markup
9
10
  end
10
11
 
11
12
  def push(tagname, attrs)
12
- @stack << PendingBlock.from_tag(tagname, attrs, @nodes.dup, @list_depth)
13
+ @stack << PendingBlock.from_tag(tagname, attrs, @nodes.dup, @list_depth, is_semantic_markup: @is_semantic_markup)
13
14
  track_block_node(tagname)
14
15
  end
15
16
 
@@ -1,7 +1,7 @@
1
1
  module DraftjsHtml
2
2
  class FromHtml < Nokogiri::XML::SAX::Document
3
- PendingBlock = Struct.new(:tagname, :attrs, :chars, :entities, :pending_entities, :parent_tagnames, :depth, keyword_init: true) do
4
- def self.from_tag(name, attrs, parent_tagnames, depth)
3
+ PendingBlock = Struct.new(:tagname, :attrs, :chars, :entities, :pending_entities, :parent_tagnames, :depth, :is_semantic_markup, keyword_init: true) do
4
+ def self.from_tag(name, attrs, parent_tagnames, depth, is_semantic_markup: true)
5
5
  self.new(
6
6
  tagname: name,
7
7
  attrs: attrs,
@@ -10,6 +10,7 @@ module DraftjsHtml
10
10
  pending_entities: [],
11
11
  depth: depth,
12
12
  parent_tagnames: parent_tagnames,
13
+ is_semantic_markup: is_semantic_markup,
13
14
  )
14
15
  end
15
16
 
@@ -23,7 +24,8 @@ module DraftjsHtml
23
24
 
24
25
  def flushable?
25
26
  %w[OPENING ol ul li table].include?(parent_tagnames.last) ||
26
- (parent_tagnames.last == 'div' && tagname != 'div')
27
+ (parent_tagnames.last == 'div' && tagname != 'div') ||
28
+ (!is_semantic_markup && tagname == 'div')
27
29
  end
28
30
 
29
31
  def consume(other_pending_block)
@@ -11,7 +11,7 @@ module DraftjsHtml
11
11
  def initialize(options = {})
12
12
  @draftjs = Draftjs::RawBuilder.new
13
13
  @parser = Nokogiri::HTML4::SAX::Parser.new(self)
14
- @depth_stack = DepthStack.new
14
+ @depth_stack = DepthStack.new(is_semantic_markup: options.fetch(:is_semantic_markup, true))
15
15
  @options = ensure_options!(options.dup)
16
16
  end
17
17
 
@@ -43,7 +43,7 @@ module DraftjsHtml
43
43
 
44
44
  ENTITY_CONVERSION_MAP = {
45
45
  'LINK' => ->(entity, content, *) {
46
- attributes = entity.data.slice('url', 'href', 'rel', 'target', 'title', 'className').each_with_object({}) do |(attr, value), h|
46
+ attributes = entity.data.slice('href', 'url', 'rel', 'target', 'title', 'className').each_with_object({}) do |(attr, value), h|
47
47
  h[ENTITY_ATTRIBUTE_NAME_MAP.fetch(attr, attr)] = value
48
48
  end
49
49
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DraftjsHtml
4
- VERSION = "0.22.0"
4
+ VERSION = "0.24.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.22.0
4
+ version: 0.24.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-12-15 00:00:00.000000000 Z
11
+ date: 2022-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri