draftjs_html 0.19.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: cc60a020f5dbdf759d93345fbc5589476a156d18d5c7b793fa7d1ebb36bb4164
4
- data.tar.gz: fce62ecfe77aa2740b895fc38ec45b0d2947f47dcb202d217d9e07ec3644f791
3
+ metadata.gz: 662afcc40856fc071f8933862c939e45da447bfcf089287ef486c20eaa9ad9ea
4
+ data.tar.gz: e3c86eb5fd81a6daf446d3cd6a2a8394d4db8c2a79a4d7e3dfc9aa0ff1524514
5
5
  SHA512:
6
- metadata.gz: 06e33f852881f2f5f02edf2afdf331caa0d5fa208a0d0386a6e9eaa663eb2b11694cb3d6c942ca4cfde17edd0379ecd3d3e8abe061970494002d743f1468eed7
7
- data.tar.gz: 128b6ec7334c9909c209e18146e96aad8b336f8af000daefc38fa8fdbb171270d4cfa4458365326e13f33c2b155119091907ce63b08ae17739d6791c111eb3a5
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.
@@ -26,9 +26,13 @@ module DraftjsHtml
26
26
  'small' => 'SMALL',
27
27
  'sub' => 'SUBSCRIPT',
28
28
  'sup' => 'SUPERSCRIPT',
29
+ 'code' => 'CODE',
29
30
  }.freeze
30
31
 
31
- 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
32
36
 
33
37
  ENTITY_ATTRIBUTE_NAME_MAP = {
34
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.19.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.19.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