function isSelectionValid(selection) {
  var divTag = '<div>';   
  var isValid = false;
  var emptyElementsRegex = /<[^\/>][^>]*><\/[^>]+>/g;
  var contentElementsRegex = /<(div|p|h1|h2|h3|h4|h5|h6|ul|li|ol)[^>]*>/g;

  if (!selection || selection.isCollapsed || !selection.rangeCount) {
      return isValid;
  }
  if (selection.toString().trim() !== '') {
    var selectedHTML = getSelectedHTML(selection);
    var parentNode = getParentNode(selection);
    if(getParentNode(selection) === '') {
      return isValid;
    }
    var cleanedSelectedHTML = selectedHTML.toString().replace(emptyElementsRegex, '');
    isValid = !cleanedSelectedHTML.match(divTag) && cleanedSelectedHTML.match(contentElementsRegex) < 2;

    return isValid;
  }
}
// checks selected text for empty tags and block elements
checks selected text for empty tags and block elements
checks selected text for empty tags and block elements
function isSelectionValid(selection) {
  var divTag = '<div>';   
  var isValid = false;
  var emptyElementsRegex = /<[^\/>][^>]*><\/[^>]+>/g;
  var contentElementsRegex = /<(div|p|h1|h2|h3|h4|h5|h6|ul|li|ol)[^>]*>/g;
  if (!selection || selection.isCollapsed || !selection.rangeCount) {
      return isValid;
  }
  if (selection.toString().trim() !== '') {
    var selectedHTML = getSelectedHTML(selection);
    var parentNode = getParentNode(selection);
    if(getParentNode(selection) === '') {
      return isValid;
    }
    var cleanedSelectedHTML = selectedHTML.toString().replace(emptyElementsRegex, '');
    isValid = !cleanedSelectedHTML.match(divTag) && cleanedSelectedHTML.match(contentElementsRegex) < 2;
    return isValid;
  }
}
function isSelectionValid ( selection ) { var divTag = '<div>' ; var isValid = false ; var emptyElementsRegex = / <[^\/>][^>]*><\/[^>]+> / g ; var contentElementsRegex = / <(div|p|h1|h2|h3|h4|h5|h6|ul|li|ol)[^>]*> / g ; if ( ! selection || selection . isCollapsed || ! selection . rangeCount ) { return isValid ; } if ( selection . toString ( ) . trim ( ) !== '' ) { var selectedHTML = getSelectedHTML ( selection ) ; var parentNode = getParentNode ( selection ) ; if ( getParentNode ( selection ) === '' ) { return isValid ; } var cleanedSelectedHTML = selectedHTML . toString ( ) . replace ( emptyElementsRegex , '' ) ; isValid = ! cleanedSelectedHTML . match ( divTag ) && cleanedSelectedHTML . match ( contentElementsRegex ) < 2 ; return isValid ; } }
checks selected text for empty tags and block elements
checks selected text for empty tags and block elements