I believe this is ultimately what is responsible:

        xml_object = self.definition_to_xml(resource_fs)
        self.__class__.clean_metadata_from_xml(xml_object)  <!-- HERE

        # Set the tag so we get the file path right
        xml_object.tag = self.category <!-- HERE

I'd like to push back on this, because I believe that serializing out HTML code should go in a separate file in all cases. In 99% of the cases, an HTML block like:

     some text &lt;img src='/static/foo.jpg'&gt;

Would end up being put into a separate file since it's not XML parseable.