draftjs_html 0.9.0 → 0.10.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: 4955cd2cbaade2ea9ae659cb65028e4097fb1d8d95d5058bc165e758f40e7794
4
- data.tar.gz: 5bf0f0fbf4e6e73eb3da8b069fe536505a56db67cfed802c04baa2079a8641ff
3
+ metadata.gz: 80c53506fa59d06daa51517049055d61a21740a9cb6f68d7cc04a22fc40d116c
4
+ data.tar.gz: 9e678df882452e6917e88250884619e242ea38a28bd61a33c1bbdfb9c2ffc6f8
5
5
  SHA512:
6
- metadata.gz: a36d06cdc9383a8c27d3d93c08fc59c4a022120aa9951cdf6e9774f0fc77f3e69439ea761a6765469b0f9a4c4879b76b216b465473894b35fbd7e57b5e5ff740
7
- data.tar.gz: 16c84f495363d08c997b55de7f53b496d8f92760c936a755c1c1960d024bae7e9fb3235bcbcdb32d05649dc2668c16d4833577fce9b9861273a32f7cae33082a
6
+ metadata.gz: b866a4dc37c5c776c174fafb0cd87f110d386a692e97d39147bbb74669ce0a5ed9b50c8bf250cc6bf58bc7e5db05291d156053131c15e96f2be95c5ca2e31af9
7
+ data.tar.gz: c53aa1b233e2a4ad68a9ecdc70fe4531565c418cdaa603512e3df8ff986fcbfe0d1f1adb6590b433c285fbddcf7c18370875e17cf0d5a550b56780e0dc85d8c4
@@ -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.10.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.10.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: