commit e612ee50f2f63060e10a7d9bc91657538be7c298 parent d36ee3ac0e14377910ff7d0a42bb19345da3c8be Author: Sanjog Sharma <ssharma@milestechnologies.com> Date: Tue, 14 Jun 2022 09:33:54 -0400 prune script tag when in html view as well. fixes: https://github.com/striven-erp/striven-editor/issues/149 Diffstat:
| M | src/striveneditor.js | | | 20 | +++++++++++++------- |
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -2064,20 +2064,26 @@ export default class StrivenEditor { * Gets the content of the editor if there are attached files or provided content * @returns {String} Returns the HTML String of the editor's content */ - getContent() { + getContent() { const se = this; - - const body = se.pruneScripts(se.body); + let html=se.body; + const htmlView = !!se.editor.querySelector('.se-html'); + if(htmlView){ + let dv= document.createElement('div'); + dv.innerHTML=se.body.textContent; + + html=dv; + } + const body = se.pruneScripts(html); // Remove contenteditable tags for body [...body.querySelectorAll('[contenteditable="true"]')] .forEach(ce => ce.removeAttribute('contenteditable')); - const text = body.textContent; - if (text || se.body.getElementsByTagName('img').length) { - const htmlView = !!se.editor.querySelector('.se-html'); - return htmlView ? text : body.innerHTML; + if (body.textContent || se.body.getElementsByTagName('img').length) { + // const htmlView = !!se.editor.querySelector('.se-html'); + return body.innerHTML; } else { return null; }