draftjs_html 0.22.0 → 0.23.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: 84ac3de7f21860685dbf39a24fb921227a1ccce6d97940acd279976daab15970
4
- data.tar.gz: 2d3511eef3134a6cc01cd3da0147b3c347209c6c90ef4f5aaea90c681af979b1
3
+ metadata.gz: c01b8b4b8ca17c90c9d53f7d85caebc7fe6c18aab14a79ff635110d8a0fb81dc
4
+ data.tar.gz: 6e0d85454c9d8ee4e6998e8e398c72c01f6097fc3c5e9b61c165fb07ac01af0f
5
5
  SHA512:
6
- metadata.gz: 2775eac524063149973d4908f9f30f5e9a4d6b734f35e44b459454a95cc6a415a25a1b36daf07af3b34b1bf08b2b96c2980e6be12a9b21ed23c162100688ad03
7
- data.tar.gz: dd0c42f5271934a1a17452159e7dbad8b51bd4ad0637a9b87cf4c77b43c6ea690bdda838830d92b1fcd929e985d88958fa5bd5326af89dc3e9db76e7e84a5fe2
6
+ metadata.gz: 76cdd86c495a5900653f060f8d4f9702a29b1a7b3ebdb792b00e3f7071642c2fd7547d56aa1e3f6684ab6f873e8c377a09d8fe0c344e2ecf400db106076ebe66
7
+ data.tar.gz: 0c65eac79da80da23d667c62352542dc03717e3db1999fffb35f5a7ac19a1afe871345c1c7449dd29c0570fd780d17c1ea44f3c75b02c034e7cd224eb2c002bb
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DraftjsHtml
4
- VERSION = "0.22.0"
4
+ VERSION = "0.23.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Taylor