Skip to content

Commit

Permalink
see #881
Browse files Browse the repository at this point in the history
feature: added hooks to element and attribute removal
  • Loading branch information
cure53 committed Dec 12, 2023
1 parent f89d726 commit d7318ee
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 5 deletions.
7 changes: 7 additions & 0 deletions dist/purify.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.cjs.js.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions dist/purify.es.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,9 @@ function createDOMPurify() {
arrayPush(DOMPurify.removed, {
element: node
});
/* Execute a hook if present */

_executeHook('uponRemoveElement', node, null);

try {
// eslint-disable-next-line unicorn/prefer-dom-node-remove
Expand Down Expand Up @@ -908,6 +911,10 @@ function createDOMPurify() {
from: node
});
}
/* Execute a hook if present */


_executeHook('uponRemoveAttribute', node, null);

node.removeAttribute(name); // We void attribute values for unremovable "is"" attributes

Expand Down
2 changes: 1 addition & 1 deletion dist/purify.es.mjs.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions dist/purify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/purify.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/purify.min.js.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/purify.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,10 @@ function createDOMPurify(window = getGlobal()) {
*/
const _forceRemove = function (node) {
arrayPush(DOMPurify.removed, { element: node });

/* Execute a hook if present */
_executeHook('uponRemoveElement', node, null);

try {
// eslint-disable-next-line unicorn/prefer-dom-node-remove
node.parentNode.removeChild(node);
Expand Down Expand Up @@ -811,6 +815,9 @@ function createDOMPurify(window = getGlobal()) {
});
}

/* Execute a hook if present */
_executeHook('uponRemoveAttribute', node, null);

node.removeAttribute(name);

// We void attribute values for unremovable "is"" attributes
Expand Down

0 comments on commit d7318ee

Please sign in to comment.