Strip out MS Word html tags on migrate I've got a migration set up whose source was apparently filled out using MS Word. The JSON source for the migration looks like this in places:

{
    "field_courses": "&lt;p class=\"MsoNormal\" style=\"line-height: 14pt; background-position: initial initial; background-repeat: initial initial;\"&gt;&lt;u&gt;&lt;span style=\"font-size:10.0pt;&amp;#10;font-family:\" new=\"\"&gt;Courses Taught (selected)&lt;br /&gt;\r\n&lt;/span&gt;&lt;/u&gt;...&lt;/p&gt;"
}


When the migration completes and I open the resulting node, the field is rendered like this:



The field in question is allowed to use everything from Plain Text all the way to Full HTML. When I save the node manually, not making any changes, all the nonsense is stripped out and I'm left with relatively sane HTML when I check out the source of that field.

I thought maybe it would be as simple as loading the entity by its pathauto alias (eg. /people/[person_id]) and running $entity-&gt;save() on it as soon as it's been imported, but that's not removing the formatting. Any way that I can get it to display correctly without requiring a content manager to manually save 500+ nodes?
Found a great way to do this automatically after comparing the Devel tab on a node before and after manually saving it. I realize this is a somewhat narrow use case, but I think it's pretty strong nonetheless.


Create a CKEditor profile (I called it "Bio Cleaner", machine name bio_cleaner) and limit it to the tags and attributes you want. In my case, it's &lt;a href hreflang&gt; &lt;ul type&gt; &lt;ol start type&gt; &lt;li&gt; &lt;br&gt; &lt;p&gt;.
For any "formatted" text field in your content types, add the new CKEditor profile as an allowed profile.
In your migration, rather than just dumping the raw contents into a field name, set it up like so:




(Sorry for the image - Stack Exchange apparently can't format yaml?)

Anyway, the secret sauce is to to set the /value key of the target field to the value pulled from the migration, and to set the /format key to the new format you created. Drupal will automagically clean up whatever tags aren't included in your profile when it saves the data.

NOTE: this relies on having the Allowed Formats module installed.