From 21d9c8228aaafc51675ca69c52e831cb22a694e6 Mon Sep 17 00:00:00 2001 From: Jayesh Deorukhkar Date: Wed, 10 Jan 2024 12:24:33 +0530 Subject: [PATCH] fix: remove innerHTML using the ownerDocument key --- src/fromRedactor.tsx | 6 +++--- test/fromRedactor.test.ts | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/fromRedactor.tsx b/src/fromRedactor.tsx index 0de9626..5bb4d6c 100644 --- a/src/fromRedactor.tsx +++ b/src/fromRedactor.tsx @@ -235,20 +235,20 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject const thead = el.querySelector('thead') if (!tbody && !thead) { - el.innerHTML += "" + el.append(el.ownerDocument.createElement('tbody')) } } else if (['TBODY', 'THEAD'].includes(el.nodeName)) { const row = el.querySelector('tr') if (!row) { - el.innerHTML += "" + 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}>` + el.append(el.ownerDocument.createElement(cellType)) } } diff --git a/test/fromRedactor.test.ts b/test/fromRedactor.test.ts index 30a47d8..44a20e9 100644 --- a/test/fromRedactor.test.ts +++ b/test/fromRedactor.test.ts @@ -332,4 +332,8 @@ function htmlToJson (html, options) { let htmlDoc = dom.window.document.querySelector("body"); return fromRedactor(htmlDoc, options); -} \ No newline at end of file +} + +test("test", () => { + console.log("%j", htmlToJson(`
`)) +}) \ No newline at end of file