Skip to content

Commit

Permalink
fix: remove innerHTML using the ownerDocument key
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayesh2812 committed Jan 10, 2024
1 parent 102ae27 commit 21d9c82
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/fromRedactor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,20 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
const thead = el.querySelector('thead')

if (!tbody && !thead) {
el.innerHTML += "<tbody></tbody>"
el.append(el.ownerDocument.createElement('tbody'))
}
}
else if (['TBODY', 'THEAD'].includes(el.nodeName)) {
const row = el.querySelector('tr')
if (!row) {
el.innerHTML += "<tr></tr>"
el.append(el.ownerDocument.createElement('tr'))
}
}
else if (el.nodeName === 'TR') {
const cell = el.querySelector('th, td')
if (!cell) {
const cellType = el.parentElement.nodeName === 'THEAD' ? 'th' : 'td'
el.innerHTML += `<${cellType}></${cellType}>`
el.append(el.ownerDocument.createElement(cellType))

}
}
Expand Down
6 changes: 5 additions & 1 deletion test/fromRedactor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,8 @@ function htmlToJson (html, options) {
let htmlDoc = dom.window.document.querySelector("body");
return fromRedactor(htmlDoc, options);

}
}

test("test", () => {
console.log("%j", htmlToJson(`<table></table>`))
})

0 comments on commit 21d9c82

Please sign in to comment.