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 afc8f95750cae22f3ca7ddd5cccb710bcd697c0b
parent fbda1f263c2938015da9507dd53d54bceaa00df3
Author: Henry Unite <unitehenry@gmail.com>
Date:   Tue,  8 Sep 2020 10:10:29 -0400

better format

Diffstat:
Msrc/striveneditor.js | 23++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -289,13 +289,26 @@ export default class StrivenEditor { case 'removeFormat': const range = this.getRange(); - const { tagName } = range.commonAncestorContainer; - if(tagName && (tagName === 'OL' || tagName === 'UL')) { - range.commonAncestorContainer.innerHTML = range.commonAncestorContainer.textContent; - return; - } + const { commonAncestorContainer } = range; + const { tagName } = commonAncestorContainer; + + if(commonAncestorContainer) { + + if(tagName && (tagName === 'OL' || tagName === 'UL')) { + commonAncestorContainer.innerHTML = commonAncestorContainer.textContent; + return; + } + const { parentElement } = commonAncestorContainer; + const formatTags = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6']; + if(formatTags.includes(parentElement.tagName)) { + parentElement.outerHTML = parentElement.textContent; + return; + } + + } + const textNode = document.createTextNode( range.toString() ); range.deleteContents(); range.insertNode(textNode);