From 01e04af8a06a48caf3e5eb3501e5db32b53634c8 Mon Sep 17 00:00:00 2001 From: Tyson Adams Date: Thu, 5 Jul 2018 13:15:07 +1000 Subject: [PATCH] Revert "Added settings for stripExtraBrTags and keepEmptyTags" This reverts commit b7ea74ac28cf0db82104d258ad502e276bd05cc5. --- Lib/Viper.js | 128 ++++++++++++++++++++++----------------------------- 1 file changed, 54 insertions(+), 74 deletions(-) diff --git a/Lib/Viper.js b/Lib/Viper.js index ead3a7d8..07312463 100755 --- a/Lib/Viper.js +++ b/Lib/Viper.js @@ -48,8 +48,6 @@ } this.setSetting('emptyTableCellContent', '
'); - this.setSetting('stripExtraBrTags', true); - this.setSetting('keepEmptyTags', []); this.init(); @@ -65,7 +63,6 @@ } if (options) { - var self = this; this._processOptions(options, function() { if (callback) { @@ -4552,31 +4549,57 @@ switch (tagName) { case 'br': + if (!node.nextSibling + || (node.hasAttribute && node.hasAttribute('_moz_dirty')) + ) { + if (!node.previousSibling + && (Viper.Util.isTag(node.parentNode, 'td') === true + || Viper.Util.isTag(node.parentNode, 'th') === true) + ) { + // This BR element is the only child of the table cell, + // depending on emptyTableCellContent, set the cell's + // content. + var emptyTableCellContent = this.getSetting('emptyTableCellContent'); + Viper.Util.setHtml(node.parentNode, emptyTableCellContent); + return; + } - /** - * @todo - * */ - - var stripExtraBrTags = this.getSetting('stripExtraBrTags'); + // Remove all BR tags and spaces just before this one. + var prev = node.previousSibling; + while (prev) { + if (Viper.Util.isTag(prev, 'br') === true + || (prev.nodeType === Viper.Util.TEXT_NODE && Viper.Util.trim(prev.nodeValue) === '') + ) { + var removeNode = prev; + prev = prev.previousSibling; + Viper.Util.remove(removeNode); + } else { + break; + } + } - if(stripExtraBrTags) { + if (tag) { + var newNode = Viper.document.createTextNode(' '); + Viper.Util.insertBefore(node, newNode); + } - if (!node.nextSibling - || (node.hasAttribute && node.hasAttribute('_moz_dirty')) - ) { - if (!node.previousSibling - && (Viper.Util.isTag(node.parentNode, 'td') === true - || Viper.Util.isTag(node.parentNode, 'th') === true) - ) { - // This BR element is the only child of the table cell, - // depending on emptyTableCellContent, set the cell's - // content. - var emptyTableCellContent = this.getSetting('emptyTableCellContent'); - Viper.Util.setHtml(node.parentNode, emptyTableCellContent); - return; + Viper.Util.remove(node); + } else { + // Also remove the br tags that are at the end of an element. + // They are usually added to give the empty element height/width. + var next = node.nextSibling; + var brLast = true; + while (next) { + if (next.nodeType !== Viper.Util.TEXT_NODE || Viper.Util.trim(next.nodeValue) !== '') { + brLast = false; + break; } - // Remove all BR tags and spaces just before this one. + next = next.nextSibling; + } + + if (brLast === true) { + // Rmove all BR tags just before this one. var prev = node.previousSibling; while (prev) { if (Viper.Util.isTag(prev, 'br') === true @@ -4589,53 +4612,13 @@ break; } } - - - if (tag) { - var newNode = Viper.document.createTextNode(' '); - Viper.Util.insertBefore(node, newNode); - } Viper.Util.remove(node); - } else { - // Also remove the br tags that are at the end of an element. - // They are usually added to give the empty element height/width. - - var next = node.nextSibling; - var brLast = true; - while (next) { - if (next.nodeType !== Viper.Util.TEXT_NODE || Viper.Util.trim(next.nodeValue) !== '') { - brLast = false; - break; - } - - next = next.nextSibling; - } - - if (brLast === true) { - // Rmove all BR tags just before this one. - var prev = node.previousSibling; - while (prev) { - if (Viper.Util.isTag(prev, 'br') === true - || (prev.nodeType === Viper.Util.TEXT_NODE && Viper.Util.trim(prev.nodeValue) === '') - ) { - var removeNode = prev; - prev = prev.previousSibling; - Viper.Util.remove(removeNode); - } else { - break; - } - } - - Viper.Util.remove(node); - } else if (Viper.Util.isTag(node.nextSibling, ['ol', 'ul']) === true && Viper.Util.isTag(node.parentNode, 'li') === true) { - // BR before sublist. - Viper.Util.remove(node); - } - - }//end if - - } + } else if (Viper.Util.isTag(node.nextSibling, ['ol', 'ul']) === true && Viper.Util.isTag(node.parentNode, 'li') === true) { + // BR before sublist. + Viper.Util.remove(node); + } + }//end if break; case 'a': @@ -4685,13 +4668,10 @@ default: var cont = Viper.Util.trim(Viper.Util.getHtml(node)); - - var keepEmptyTags = this.getSetting('keepEmptyTags'); - - if (Viper.Util.isTag(node, keepEmptyTags) === false - && ((Viper.Util.isStubElement(node) === false && !node.firstChild) + if ((Viper.Util.isStubElement(node) === false + && !node.firstChild) || cont === ' ' - || (cont === '')) + || (cont === '' && Viper.Util.isTag(node, ['p', 'div'])) ) { if (this.isSpecialElement(node) !== true) { Viper.Util.remove(node);