Skip to content

Commit 3346a0c

Browse files
committed
fix: remove innerHTML using the ownerDocument key
1 parent 7e4aea1 commit 3346a0c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/fromRedactor.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,20 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
235235
const thead = el.querySelector('thead')
236236

237237
if (!tbody && !thead) {
238-
el.innerHTML += "<tbody></tbody>"
238+
el.append(el.ownerDocument.createElement('tbody'))
239239
}
240240
}
241241
else if (['TBODY', 'THEAD'].includes(el.nodeName)) {
242242
const row = el.querySelector('tr')
243243
if (!row) {
244-
el.innerHTML += "<tr></tr>"
244+
el.append(el.ownerDocument.createElement('tr'))
245245
}
246246
}
247247
else if (el.nodeName === 'TR') {
248248
const cell = el.querySelector('th, td')
249249
if (!cell) {
250250
const cellType = el.parentElement.nodeName === 'THEAD' ? 'th' : 'td'
251-
el.innerHTML += `<${cellType}></${cellType}>`
251+
el.append(el.ownerDocument.createElement(cellType))
252252

253253
}
254254
}

test/fromRedactor.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,8 @@ function htmlToJson (html, options) {
332332
let htmlDoc = dom.window.document.querySelector("body");
333333
return fromRedactor(htmlDoc, options);
334334

335-
}
335+
}
336+
337+
test("test", () => {
338+
console.log("%j", htmlToJson(`<table></table>`))
339+
})

0 commit comments

Comments
 (0)