Problem
DOMDocument is not suitable for processing HTML5 pages.
Tasks
Use a HTML5 library such as https://github.com/Masterminds/html5-php to process and inject markup.
See https://www.drupal.org/node/1333730 for further information about how this will be addressed in D8.
Comments