Add ignoreElements predicate function option

This commit is contained in:
Niklas von Hertzen
2018-02-15 21:22:51 +08:00
parent e6c44afca1
commit fad4f837c9
5 changed files with 16 additions and 7 deletions

View File

@ -268,8 +268,12 @@ export class DocumentCloner {
for (let child = node.firstChild; child; child = child.nextSibling) {
if (
child.nodeType !== Node.ELEMENT_NODE ||
// $FlowFixMe
(child.nodeName !== 'SCRIPT' && !child.hasAttribute(IGNORE_ATTRIBUTE))
(child.nodeName !== 'SCRIPT' &&
// $FlowFixMe
!child.hasAttribute(IGNORE_ATTRIBUTE) &&
(typeof this.options.ignoreElements !== 'function' ||
// $FlowFixMe
!this.options.ignoreElements(child)))
) {
if (!this.copyStyles || child.nodeName !== 'STYLE') {
clone.appendChild(this.cloneNode(child));

View File

@ -14,6 +14,7 @@ export type Options = {
backgroundColor: string,
canvas: ?HTMLCanvasElement,
foreignObjectRendering: boolean,
ignoreElements?: HTMLElement => boolean,
imageTimeout: number,
logging: boolean,
proxy: ?string,