draftjs_html 0.9.0 → 0.11.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: 4955cd2cbaade2ea9ae659cb65028e4097fb1d8d95d5058bc165e758f40e7794
4
- data.tar.gz: 5bf0f0fbf4e6e73eb3da8b069fe536505a56db67cfed802c04baa2079a8641ff
3
+ metadata.gz: 97e119deceb20067af8250c02562af382ec70c22842ecba90030f869f96d72ff
4
+ data.tar.gz: 22dcc02184bd9bd7a8076b221035bc4d77e83d04a683d6b790a33692c8a6b0b3
5
5
  SHA512:
6
- metadata.gz: a36d06cdc9383a8c27d3d93c08fc59c4a022120aa9951cdf6e9774f0fc77f3e69439ea761a6765469b0f9a4c4879b76b216b465473894b35fbd7e57b5e5ff740
7
- data.tar.gz: 16c84f495363d08c997b55de7f53b496d8f92760c936a755c1c1960d024bae7e9fb3235bcbcdb32d05649dc2668c16d4833577fce9b9861273a32f7cae33082a
6
+ metadata.gz: 5c52bb41b0d401101e711e9ab9661ae427b20a6fb42579f1fe6030ed319a712878161ef57866dbde9901acaa7ef58ea644ce0ee4b8fc2ffe7308a0c1f49429fc
7
+ data.tar.gz: 5f1cc51bea08ee82bc8e2f6ff34226dffad2fc51666dd88bbb15d37bd4de093d5e10441a5bbb39c2c9498193ed8dd50d6d5e2ef0b8f9867bc73998c2626aae3c
@@ -16,6 +16,7 @@ module DraftjsHtml
16
16
  {
17
17
  'text' => block.text,
18
18
  'type' => block.type,
19
+ 'depth' => block.depth,
19
20
  'inlineStyleRanges' => block.inline_styles.map { { 'style' => _1.name, 'offset' => _1.offset, 'length' => _1.length } },
20
21
  'entityRanges' => block.entity_ranges.map { { 'key' => _1.name, 'offset' => _1.offset, 'length' => _1.length } },
21
22
  }
@@ -2,6 +2,7 @@ require_relative 'node'
2
2
  require_relative 'html_depth'
3
3
  require_relative 'html_defaults'
4
4
  require_relative 'overrideable_map'
5
+ require_relative 'unicode_rtl_detector'
5
6
 
6
7
  module DraftjsHtml
7
8
  class ToHtml
@@ -55,7 +56,9 @@ module DraftjsHtml
55
56
  end
56
57
 
57
58
  def append_child(nokogiri, child)
58
- nokogiri.parent.add_child(DraftjsHtml::Node.of(child).to_nokogiri(@document.doc))
59
+ new_node = DraftjsHtml::Node.of(child).to_nokogiri(@document.doc)
60
+ nokogiri.parent['dir'] = 'rtl' if UnicodeRtlDetector.new.contains_rtl?(new_node.inner_text)
61
+ nokogiri.parent.add_child(new_node)
59
62
  end
60
63
 
61
64
  def block_element_for(block)
@@ -0,0 +1,27 @@
1
+ module DraftjsHtml
2
+ class UnicodeRtlDetector
3
+ # This regex was copied from fbjs's UnicodeBidi detection
4
+ # See https://github.com/facebook/fbjs/blob/main/packages/fbjs/src/unicode/UnicodeBidi.js.
5
+ STRONG_RTL_CHAR_RANGES = [
6
+ '\u0590\u05BE\u05C0\u05C3\u05C6\u05C8-\u05CF\u05D0-\u05EA\u05EB-\u05EF',
7
+ '\u05F0-\u05F2\u05F3-\u05F4\u05F5-\u05FF\u07C0-\u07C9\u07CA-\u07EA',
8
+ '\u07F4-\u07F5\u07FA\u07FB-\u07FF\u0800-\u0815\u081A\u0824\u0828',
9
+ '\u082E-\u082F\u0830-\u083E\u083F\u0840-\u0858\u085C-\u085D\u085E',
10
+ '\u085F-\u089F\u200F\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB37\uFB38-\uFB3C',
11
+ '\uFB3D\uFB3E\uFB3F\uFB40-\uFB41\uFB42\uFB43-\uFB44\uFB45\uFB46-\uFB4F',
12
+ '\u0608\u060B\u060D\u061B\u061C\u061D\u061E-\u061F\u0620-\u063F\u0640',
13
+ '\u0641-\u064A\u066D\u066E-\u066F\u0671-\u06D3\u06D4\u06D5\u06E5-\u06E6',
14
+ '\u06EE-\u06EF\u06FA-\u06FC\u06FD-\u06FE\u06FF\u0700-\u070D\u070E\u070F',
15
+ '\u0710\u0712-\u072F\u074B-\u074C\u074D-\u07A5\u07B1\u07B2-\u07BF',
16
+ '\u08A0-\u08B2\u08B3-\u08E3\uFB50-\uFBB1\uFBB2-\uFBC1\uFBC2-\uFBD2',
17
+ '\uFBD3-\uFD3D\uFD40-\uFD4F\uFD50-\uFD8F\uFD90-\uFD91\uFD92-\uFDC7',
18
+ '\uFDC8-\uFDCF\uFDF0-\uFDFB\uFDFC\uFDFE-\uFDFF\uFE70-\uFE74\uFE75',
19
+ '\uFE76-\uFEFC\uFEFD-\uFEFE',
20
+ ].join.freeze
21
+ RTL_MATCHER = /[#{STRONG_RTL_CHAR_RANGES}]/
22
+
23
+ def contains_rtl?(text)
24
+ RTL_MATCHER.match?(text)
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DraftjsHtml
4
- VERSION = "0.9.0"
4
+ VERSION = "0.11.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.9.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Taylor
@@ -70,6 +70,7 @@ files:
70
70
  - lib/draftjs_html/node.rb
71
71
  - lib/draftjs_html/overrideable_map.rb
72
72
  - lib/draftjs_html/to_html.rb
73
+ - lib/draftjs_html/unicode_rtl_detector.rb
73
74
  - lib/draftjs_html/version.rb
74
75
  homepage: https://github.com/dugancathal/draftjs_html
75
76
  licenses: