public function loadFragment($source, $contentType, $options = [])
{
if ($this->supports($contentType)) {
$options = $this->getOptions($options);
$loadOptions = (int) $options[self::LIBXML_OPTIONS];
return $this->captureLibxmlErrors(function () use($source, $loadOptions) {
$document = new Document();
$fragment = $document->createDocumentFragment();
$document->loadHTML('<html-fragment>' . $source . '</html-fragment>', $loadOptions);
$nodes = $document->evaluate('//html-fragment[1]/node()');
foreach ($nodes as $node) {
$fragment->append($node);
}
return $fragment;
});
}
return NULL;
}