striven-editor

Maintained and contributed to an open source WYSIWYG editor as an internship project that made it to production and was adopted by the company I was working at.
git clone https://unitehenry.com/git/striven-editor.git
Log | Files | Refs | README | LICENSE

commit cd8f5b9eb052d20b015b39efebc5b05636064a9f
parent 0ebcaec3e7b6b369153ba9f180b6ac6263fe2eb4
Author: unitehenry <unitehenry@gmail.com>
Date:   Tue,  3 Dec 2019 08:43:52 -0500

pruneScripts pruneInlineStyles

Diffstat:
Msrc/striveneditor.js | 22++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -1093,7 +1093,11 @@ export default class StrivenEditor { getContent() { // this.setLinkTarget(); - const cleanBody = this.pruneScripts(this.body); + let cleanBody = this.body; + cleanBody = this.pruneScripts(cleanBody); + cleanBody = this.pruneStyles(cleanBody); + cleanBody = this.pruneInlineStyles(cleanBody); + const text = cleanBody.textContent; if (text || cleanBody.getElementsByTagName('img').length) { @@ -1156,12 +1160,26 @@ export default class StrivenEditor { } pruneScripts(el) { - const scripts = el.querySelectorAll('script'); + const scripts = [...el.querySelectorAll('script')]; scripts.forEach(script => script.remove()); return el; } + pruneStyles(el) { + const styles = [...el.querySelectorAll('style')]; + styles.forEach(style => style.remove()); + + return el; + } + + pruneInlineStyles(el) { + let inlineStyleNodes = [...el.querySelectorAll("[style]")]; + inlineStyleNodes = inlineStyleNodes.filter(node => node.style.position); + inlineStyleNodes.forEach(node => node.style.position = 'static'); + return el; + } + formatBytes(bytes, decimals = 2) { if (bytes === 0) return '0 Bytes';