Skip to content

Commit

Permalink
Revert "Added settings for stripExtraBrTags and keepEmptyTags"
Browse files Browse the repository at this point in the history
This reverts commit b7ea74a.
  • Loading branch information
dozeroshi committed Jul 5, 2018
1 parent e1f84e3 commit 01e04af
Showing 1 changed file with 54 additions and 74 deletions.
128 changes: 54 additions & 74 deletions Lib/Viper.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
}

this.setSetting('emptyTableCellContent', '<br />');
this.setSetting('stripExtraBrTags', true);
this.setSetting('keepEmptyTags', []);

this.init();

Expand All @@ -65,7 +63,6 @@
}

if (options) {

var self = this;
this._processOptions(options, function() {
if (callback) {
Expand Down Expand Up @@ -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
Expand All @@ -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':
Expand Down Expand Up @@ -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 === '&nbsp;'
|| (cont === ''))
|| (cont === '' && Viper.Util.isTag(node, ['p', 'div']))
) {
if (this.isSpecialElement(node) !== true) {
Viper.Util.remove(node);
Expand Down

0 comments on commit 01e04af

Please sign in to comment.