draftjs_html 0.20.0 → 0.21.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: 4b5496551a743763154bdec10a56591d3369eb6361c863ebc0e2defd95dd539e
4
- data.tar.gz: 714eb86046e0008bc944a18edcb4137ec5034401c9a5df7e02140a7b634289c7
3
+ metadata.gz: 662afcc40856fc071f8933862c939e45da447bfcf089287ef486c20eaa9ad9ea
4
+ data.tar.gz: e3c86eb5fd81a6daf446d3cd6a2a8394d4db8c2a79a4d7e3dfc9aa0ff1524514
5
5
  SHA512:
6
- metadata.gz: a90d95f982a2bc56c1ab87326aa9226229ed8676920cd26c01f6cf3711910f85405c802fb8c707bec1ecae16b6d86dcd750dd92c9bab2fb7dafd158ddeaa7ecb
7
- data.tar.gz: 7232b75cb4d677c5cc9ea3e38e5d605a4d3d7bde1ec7842405b025e21fa2d5145a2317eebb1a72f88a0555c63123bb660c695750b2111ac60ec9fb5b27875a2d
6
+ metadata.gz: 91d4da6dd384c6b38fda6edaa8653af2a968b04e53ab3b0bdc4b1305242043f816c25f906508fb6800ab306bbe8967d6608e3a411294152b53c22f375b0cf6dd
7
+ data.tar.gz: 8840930b9e1d680477ca458b7b44faff3343dfd1d4129b4e28c931e62c2318dddee8d8c4f8c32bf1f5eaa13e8b542f6704b09ee766c95c9049b9bfa4d37441cf
data/README.md CHANGED
@@ -127,6 +127,20 @@ DraftjsHtml.to_html(raw_draftjs, options: {
127
127
  # This would generate <strong> tags instead of <b> tags around ranges of `BOLD` inline styles.
128
128
  ```
129
129
 
130
+ You may also add attributes to tags created by `inline_style_mapping`s by using a two element array.
131
+ The first element should be the tagname and the second argument a hash of attributes to values, like this:
132
+
133
+ ```ruby
134
+
135
+ DraftjsHtml.to_html(raw_draftjs, options: {
136
+ inline_style_mapping: {
137
+ 'BOLD' => ['strong', style: 'font-weight: 900'],
138
+ },
139
+ })
140
+ ```
141
+
142
+ # This would generate <strong> tags instead of <b> tags around ranges of `BOLD` inline styles.
143
+
130
144
  #### `:inline_style_renderer`
131
145
 
132
146
  If the direct mapping from `:inline_style_mapping` isn't enough, you can supply a custom function for rendering a style range.
@@ -29,7 +29,10 @@ module DraftjsHtml
29
29
  'code' => 'CODE',
30
30
  }.freeze
31
31
 
32
- STYLE_MAP = HTML_STYLE_TAGS_TO_STYLE.invert.freeze
32
+ STYLE_MAP = HTML_STYLE_TAGS_TO_STYLE.invert.merge(
33
+ 'HIGHLIGHT' => 'em',
34
+ 'RTL' => ['div', dir: 'rtl']
35
+ ).freeze
33
36
 
34
37
  ENTITY_ATTRIBUTE_NAME_MAP = {
35
38
  'className' => 'class',
@@ -49,7 +49,8 @@ module DraftjsHtml
49
49
  return append_child(html, custom_render_content) if custom_render_content
50
50
 
51
51
  style, *rest = style_names
52
- html.public_send(style_element_for(style)) do |builder|
52
+
53
+ html.public_send(*style_element_for(style)) do |builder|
53
54
  apply_styles_to(builder, rest, child)
54
55
  end
55
56
  end
@@ -78,7 +79,7 @@ module DraftjsHtml
78
79
  end
79
80
 
80
81
  def style_element_for(style)
81
- @options[:inline_style_mapping].value_of!(style)
82
+ Array(@options[:inline_style_mapping].value_of!(style))
82
83
  end
83
84
 
84
85
  def try_apply_entity_to(draftjs, char_range)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DraftjsHtml
4
- VERSION = "0.20.0"
4
+ VERSION = "0.21.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.20.0
4
+ version: 0.21.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-11-17 00:00:00.000000000 Z
11
+ date: 2022-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri