Migrating style and script tags from node bodies into Code per Node

For a recent project, I needed to migrate anything inside


Thanks Jeff.

You taught me something with the reference to the Migrate modules prepare() function.
This approach could be useful for many other migration / cleanups tasks.

All the best,

I came across this when I released Inline CSS Checker and got pointed by @DamienMcKenna to CPN, which has a link to this post.

Besides using regexes, another option in some cases might be to use DOMDocument and DOMXPath as I did. I'm not 100% sure if DOMDocument::saveHTML() renders the HTML the same way it read it, though, but it seems to do a decent job.

See my note in the function comments on why I used regex; unfortunately, DOMDocument seems to not enjoy parsing any less-than-stellar HTML (for example, if someone puts a