Is there a way to programmatically clean/Redactorize HTML? I'm writing a plugin to import posts from a WordPress blog. The source post formats are inconsistent, some coming with full HTML (&lt;p&gt; tags wrapping each paragraph, etc.), while others seem to just have tags added for formatting and emphasis—newlines but no paragraphs or &lt;br&gt;'s.

 $entry-&gt;setContentFromPost(array(
     'body' =&gt; $post['content'],
 ));

 $success = craft()-&gt;entries-&gt;saveEntry($entry);


So without any adjustment, many of the imported posts look crappy on the front end when they're just dropped into a template with {{ entry.body }} (Rich Text). The missing paragraph tags look less than stellar, and they're semantically uncool as well.

Redactor handles this just fine, so viewing and saving the imported entry in Craft is a breeze. It's not ideal, however, to go back and manually re-save each entry. Is there a way to re-save a cleaned Rich Text field via Craft's API, or do I need to standardize post HTML prior to my Craft import process?
The Purify setting for the Rich Text field will run the data through HTMLPurifier, which will do its best to try and remove any malicious code from the data.

I think what you're seeing is Redactor itself cleaning the rogue HTML elements before submitting to POST/Craft.

I think it's probably going to be easier trying to clean your HTML with some custom logic/regex before saving rather than trying to figure out how to spin up Redactor to do the cleaning.