@@ -10,13 +10,12 @@ class Attributes < OpenStruct
1010 block : %i[ align bottom leading left margin_left padding_left position right top ] ,
1111 tag_close : %i[ margin_bottom padding_bottom break_after ] ,
1212 tag_open : %i[ margin_top padding_top break_before ] ,
13- text_node : %i[ background callback character_spacing color font link list_style_type size styles white_space ]
13+ text_node : %i[ callback character_spacing color font link list_style_type size styles white_space ]
1414 } . freeze
1515
1616 STYLES_LIST = {
1717 # text node styles
18- 'background' => { key : :background , set : :convert_color } ,
19- 'callback' => { key : :callback , set : :copy_value } ,
18+ 'background' => { key : :callback , set : :callback_background } ,
2019 'color' => { key : :color , set : :convert_color } ,
2120 'font-family' => { key : :font , set : :unquote } ,
2221 'font-size' => { key : :size , set : :convert_size } ,
@@ -25,7 +24,7 @@ class Attributes < OpenStruct
2524 'href' => { key : :link , set : :copy_value } ,
2625 'letter-spacing' => { key : :character_spacing , set : :convert_float } ,
2726 'list-style-type' => { key : :list_style_type , set : :unquote } ,
28- 'text-decoration' => { key : :styles , set : :append_styles } ,
27+ 'text-decoration' => { key : :styles , set : :append_text_decoration } ,
2928 'vertical-align' => { key : :styles , set : :append_styles } ,
3029 'white-space' => { key : :white_space , set : :convert_symbol } ,
3130 # tag opening styles
@@ -103,6 +102,24 @@ def parse_styles(styles)
103102
104103 private
105104
105+ def process_styles ( hash_styles , options :)
106+ hash_styles . each do |key , value |
107+ rule = evaluate_rule ( key , value )
108+ apply_rule! ( merged_styles : @styles , rule : rule , value : value , options : options )
109+ end
110+ @styles
111+ end
112+
113+ def evaluate_rule ( rule_key , attr_value )
114+ rule = STYLES_LIST [ rule_key ]
115+ if rule && rule [ :set ] == :append_text_decoration
116+ return { key : :callback , set : :callback_strike_through } if attr_value == 'line-through'
117+
118+ return { key : :styles , set : :append_styles }
119+ end
120+ rule
121+ end
122+
106123 def apply_rule! ( merged_styles :, rule :, value :, options :)
107124 return unless rule
108125
@@ -113,12 +130,5 @@ def apply_rule!(merged_styles:, rule:, value:, options:)
113130 merged_styles [ rule [ :key ] ] = Utils . send ( rule [ :set ] , value , options : opts )
114131 end
115132 end
116-
117- def process_styles ( hash_styles , options :)
118- hash_styles . each do |key , value |
119- apply_rule! ( merged_styles : @styles , rule : STYLES_LIST [ key ] , value : value , options : options )
120- end
121- @styles
122- end
123133 end
124134end
0 commit comments