Skip to content

Commit 3dca8b5

Browse files
committed
fix: RT-258 proper HTML conversion for inline properties id and class
1 parent 9bc53e8 commit 3dca8b5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/fromRedactor.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
191191
}
192192
if (el.parentNode.nodeName === 'SPAN') {
193193
let attrs = { style: {} }
194+
const metadata = {}
195+
194196
if (el.parentNode.style?.color) {
195197
attrs = {
196198
...attrs,
@@ -218,7 +220,20 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
218220
}
219221
}
220222
}
221-
return jsx('text', { attrs: attrs }, el.textContent)
223+
if(el.parentNode.getAttribute("id")){
224+
metadata['id'] = el.parentNode.getAttribute("id")
225+
el.parentNode.removeAttribute("id")
226+
}
227+
if(el.parentNode.getAttribute("class")){
228+
metadata['classname'] = el.parentNode.getAttribute("class")
229+
el.parentNode.removeAttribute("class")
230+
}
231+
232+
if(!isEmpty(attrs.style)){
233+
metadata['attrs'] = attrs
234+
}
235+
236+
return jsx('text', metadata, el.textContent)
222237
}
223238
return el.textContent
224239
} else if (el.nodeType !== 1) {

0 commit comments

Comments
 (0)