registerPastedNodesFilter

Type: Function

How to get registerPastedNodesFilter?

JavaScript

import registerPastedNodesFilter from 'fontoxml-clipboard/src/registerPastedNodesFilter.js'

Register a function to modify any XML nodes pasted from Fonto before they are included in the document.

This function is used when pasting any content that was copied either from Fonto or from anything that outputs HTML, such as the browser or other text editors such as Microsoft Word or LibreOffice Writer. The function is called with the outermost nodes of the content being pasted, as well as a Blueprint in which the nodes may be modified. It should return an array consisting of those outermost nodes that should be included in the document.

Other

// This filter removes any descendant of pasted nodes that is called `unwantedNode`
registerPastedNodesFilter((nodes, blueprint) => {
	nodes.forEach(node =>
		evaluateXPathToNodes('descendant::unwantedNode', blueprint).forEach(unwantedNode =>
			blueprint.removeChild(blueprint.getParentNode(unwantedNode), unwantedNode)
		)
	);
 return nodes.filter(node => node.nodeName !== unwantedNode);
});

Arguments

  1. filterPastedNodes

    (Required)

    Type: Function

    Callback that can remove nodes or edit them

    Arguments

    Returns