@@ -111,7 +111,7 @@ class Trix.HTMLParser extends Trix.BasicObject
111111
112112 processElement : (element ) ->
113113 if nodeIsAttachmentElement (element)
114- attributes = getAttachmentAttributes (element)
114+ attributes = parseTrixDataAttribute (element, " attachment " )
115115 if Object .keys (attributes).length
116116 textAttributes = @ getTextAttributes (element)
117117 @ appendAttachmentWithAttributes (attributes, textAttributes)
@@ -212,9 +212,8 @@ class Trix.HTMLParser extends Trix.BasicObject
212212 attributes[attribute] = value
213213
214214 if nodeIsAttachmentElement (element)
215- if json = element .getAttribute (" data-trix-attributes" )
216- for key, value of JSON .parse (json)
217- attributes[key] = value
215+ for key, value of parseTrixDataAttribute (element, " attributes" )
216+ attributes[key] = value
218217
219218 attributes
220219
@@ -237,8 +236,11 @@ class Trix.HTMLParser extends Trix.BasicObject
237236 element = element .parentNode
238237 ancestors
239238
240- getAttachmentAttributes = (element ) ->
241- JSON .parse (element .getAttribute (" data-trix-attachment" ))
239+ parseTrixDataAttribute = (element , name ) ->
240+ try
241+ JSON .parse (element .getAttribute (" data-trix-#{ name} " ))
242+ catch
243+ {}
242244
243245 getImageDimensions = (element ) ->
244246 width = element .getAttribute (" width" )
0 commit comments