Open
Description
The following code:
<?php
require 'vendor/autoload.php';
use Masterminds\HTML5;
$html = new HTML5(array(
"disable_html_ns" => false
));
$dom = $html->loadHTML(<<<HTML
<!DOCTYPE html>
<html>
<body>
<template><div>foo</div></template>
</body>
</html>
HTML);
echo $dom->saveHTML();
$xp = new DOMXPath($dom);
$xp->registerNamespace('html', 'http://www.w3.org/1999/xhtml');
var_dump($xp->query('//html:div'));
Resulted in the following output:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><body>
<template><div>foo</div></template>
</body>
</html>
object(DOMNodeList)#8 (1) {
["length"]=>
int(1)
}
But I expected this instead:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><body>
<template><div>foo</div></template>
</body>
</html>
object(DOMNodeList)#8 (1) {
["length"]=>
int(0)
}
While template contents should be serialized via saveHTML(), they should not participate in the DOM tree and therefore not show up in the DOMNodeList.
Equivalent JS:
dom=(new DOMParser).parseFromString(`<!DOCTYPE html>
<html>
<body>
<template><div>foo</div></template>
</body>
</html>`,'text/html');
console.log(dom.getElementsByTagName('template')[0].firstChild); // null
console.log(dom.documentElement.outerHTML); // Shows template contents