Add ignore option for class names (#1555)

* Add ignore option for class names

This change adds another option for ignoring nodes for rendering similar to `ignoreTags`.
The new option `ignoreClasses` can hold an array of strings representing class names that should be ignored if they are in a node's class list. This can be desirable in dynamic environments.

* Adhere to CI rules for styling

* Add documentation for new option

* Exchange classList property with IE9 compatible code

* Harmonize variable names

* Add default for ignoredClasses
This commit is contained in:
Oliver Tacke
2018-08-08 02:00:22 +02:00
committed by ylemkimon
parent 69a7634a56
commit 02639b424e
2 changed files with 9 additions and 1 deletions

View File

@@ -61,8 +61,11 @@ const renderElem = function(elem, optionsCopy) {
elem.replaceChild(frag, childNode);
} else if (childNode.nodeType === 1) {
// Element node
const className = ' ' + childNode.className + ' ';
const shouldRender = optionsCopy.ignoredTags.indexOf(
childNode.nodeName.toLowerCase()) === -1;
childNode.nodeName.toLowerCase()) === -1 &&
optionsCopy.ignoredClasses.every(
x => className.indexOf(' ' + x + ' ') === -1);
if (shouldRender) {
renderElem(childNode, optionsCopy);
@@ -90,6 +93,8 @@ const defaultAutoRenderOptions = {
"script", "noscript", "style", "textarea", "pre", "code",
],
ignoredClasses: [],
errorCallback: function(msg, err) {
console.error(msg, err);
},