How would one modify the filtering Gutenberg applies to pasted content?

In my blocks.js , located in wp-includes/js/dist/ I find the RemoveInvalidHTML function, which seems to responsible for removing styles from pasted HTML.

/**
 * Given a schema, unwraps or removes nodes, attributes and classes on HTML.
 *
 * @param {string} HTML   The HTML to clean up.
 * @param {Object} schema Schema for the HTML.
 * @param {Object} inline Whether to clean for inline mode.
 *
 * @return {string} The cleaned up HTML.
 */


function removeInvalidHTML(HTML, schema, inline) {
  var doc = document.implementation.createHTMLDocument('');
  doc.body.innerHTML = HTML;
  cleanNodeList(doc.body.childNodes, doc, schema, inline);
  return doc.body.innerHTML;
}

As you can see, this returns only the innerHTML . Modifying (creating a customized version of) this function would likely solve your problem.

Leave a Comment