Hmm, you could try experimenting with something along these lines in your child theme’s functions.php (this allows pasting in rich text, while stripping unwanted elements, but may be could be inspiration for what you’re looking for):
// Enable rich text to be pasted into TinyMCE fields
add_filter( 'submit_job_form_wp_editor_args', function( $args ) {
// Comment these lines to ENABLE the feature
// unset( $args['tinymce']['paste_auto_cleanup_on_paste'] ); // I would keep this enabled
unset( $args['tinymce']['paste_as_text'] );
// unset( $args['tinymce']['paste_remove_spans'] );
// unset( $args['tinymce']['paste_remove_styles'] );
// unset( $args['tinymce']['paste_remove_styles_if_webkit'] );
// unset( $args['tinymce']['paste_strip_class_attributes'] );
return $args;
} );
// Remove, strip, and replace tags when content is pasted into TinyMCE
add_filter('tiny_mce_before_init', 'customize_tinymce');
function customize_tinymce($in) {
$in['paste_preprocess'] = "function(pl,o){
// remove the following tags completely:
o.content = o.content.replace(/<\/*(applet|area|article|aside|audio|base|basefont|bdi|bdo|body|button|canvas|command|datalist|details|embed|figcaption|figure|font|footer|frame|frameset|head|header|hgroup|hr|html|iframe|img|keygen|link|map|mark|menu|meta|meter|nav|noframes|noscript|object|optgroup|output|param|progress|rp|rt|ruby|script|section|source|span|style|summary|time|title|track|video|wbr|table|tbody|tr|td|th|h1|h2|h3|h4|h5|h6|hr|big|code|font|blockquote|dir|address|cite|del|dfn|ins|kbd|q|samp|small|strike|sub|sup|tt|var|caption|input|dialog|fieldset|pre|a name)[^>]*>/gi,'');
// remove all attributes from these tags:
o.content = o.content.replace(/<(div|p|b|strong|i|em|ul|li|dt|dd|dl|u|s) [^>]*>/gi,'<$1>');
// keep only href in the a tag (needs to be refined to also keep _target and ID):
o.content = o.content.replace(/<a [^>]*href=(\"|')(.*?)(\"|')[^>]*>/gi,'<a href=\"$2\">');
// replace br tag with p tag:
if (o.content.match(/<br[\/\s]*>/gi)) {
o.content = o.content.replace(/<br[\s\/]*>/gi,'</p><p>');
}
// replace div tag with p tag, b tag with strong tag, and i tag with em tag:
o.content = o.content.replace(/<(\/)*div[^>]*>/gi,'<$1p>');
o.content = o.content.replace(/<(\/)*b[^>]*>/gi,'<$1strong>');
o.content = o.content.replace(/<(\/)*i[^>]*>/gi,'<$1em>');
// remove double paragraphs:
o.content = o.content.replace(/<\/p>[\s\\r\\n]+<\/p>/gi,'</p></p>');
o.content = o.content.replace(/<\<p>[\s\\r\\n]+<p>/gi,'<p><p>');
o.content = o.content.replace(/<\/p>[\s\\r\\n]+<\/p>/gi,'</p></p>');
o.content = o.content.replace(/<\<p>[\s\\r\\n]+<p>/gi,'<p><p>');
o.content = o.content.replace(/(<\/p>)+/gi,'</p>');
o.content = o.content.replace(/(<p>)+/gi,'<p>');
}";
return $in;
}
Most of this is from here (with improvements). Some seems to work, some doesn’t–I’m not familiar enough with RegEx to perfect it, unfortunately.