@@ -163,35 +163,19 @@ defmodule Keila.Templates.Html do
163
163
Apply markup transforms for improved email client compatibility.
164
164
165
165
## Transforms:
166
- - `h4 a` -> `div.keila-button a`
166
+ - `h4 a` -> `div.keila-button a` (this is implemented twice because mochihtml strips the leading " \n " while Lexbor retains it)
167
167
"""
168
168
@ spec apply_email_markup ( t ( ) ) :: t ( )
169
169
def apply_email_markup ( html ) do
170
170
Floki . traverse_and_update ( html , & do_apply_email_markup / 1 )
171
171
end
172
172
173
173
defp do_apply_email_markup ( { "h4" , _ , [ { "a" , a_attrs , a_children } ] } ) do
174
- a_attrs =
175
- case Enum . find_index ( a_attrs , & ( elem ( & 1 , 0 ) == "class" ) ) do
176
- nil ->
177
- [ { "class" , "button-a" } | a_attrs ]
178
-
179
- i ->
180
- List . update_at ( a_attrs , i , fn { "class" , classes } ->
181
- { "class" , classes <> " button-a" }
182
- end )
183
- end
174
+ build_button_markup ( a_attrs , a_children )
175
+ end
184
176
185
- { "table" , [ { "style" , "width: 100%" } ] ,
186
- [
187
- { "tr" , [ { "class" , "block--button" } ] ,
188
- [
189
- { "td" , [ { "class" , "button-td" } ] ,
190
- [
191
- { "a" , a_attrs , a_children }
192
- ] }
193
- ] }
194
- ] }
177
+ defp do_apply_email_markup ( { "h4" , _ , [ "\n " , { "a" , a_attrs , a_children } ] } ) do
178
+ build_button_markup ( a_attrs , a_children )
195
179
end
196
180
197
181
defp do_apply_email_markup ( { "blockquote" , _ , content } ) do
@@ -248,4 +232,28 @@ defmodule Keila.Templates.Html do
248
232
end
249
233
250
234
defp do_apply_email_markup ( other ) , do: other
235
+
236
+ defp build_button_markup ( a_attrs , a_children ) do
237
+ a_attrs =
238
+ case Enum . find_index ( a_attrs , & ( elem ( & 1 , 0 ) == "class" ) ) do
239
+ nil ->
240
+ [ { "class" , "button-a" } | a_attrs ]
241
+
242
+ i ->
243
+ List . update_at ( a_attrs , i , fn { "class" , classes } ->
244
+ { "class" , classes <> " button-a" }
245
+ end )
246
+ end
247
+
248
+ { "table" , [ { "style" , "width: 100%" } ] ,
249
+ [
250
+ { "tr" , [ { "class" , "block--button" } ] ,
251
+ [
252
+ { "td" , [ { "class" , "button-td" } ] ,
253
+ [
254
+ { "a" , a_attrs , a_children }
255
+ ] }
256
+ ] }
257
+ ] }
258
+ end
251
259
end
0 commit comments