From 4048a825d940001889caa6490139cbcfc118442f Mon Sep 17 00:00:00 2001 From: Tim van Dalen Date: Thu, 4 Mar 2021 19:19:18 +0100 Subject: [PATCH] Add support for @itemprop="mainEntity" top-level items --- src/Reader/MicrodataReader.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/Reader/MicrodataReader.php diff --git a/src/Reader/MicrodataReader.php b/src/Reader/MicrodataReader.php old mode 100644 new mode 100755 index 1f1e692..ff3be42 --- a/src/Reader/MicrodataReader.php +++ b/src/Reader/MicrodataReader.php @@ -31,11 +31,12 @@ public function read(DOMDocument $document, string $url) : array $xpath = new DOMXPath($document); /** - * An item is a top-level Microdata item if its element does not have an itemprop attribute. + * An item is a top-level Microdata item if its element does not have an itemprop attribute or + * if it is the mainEntity of the page. * * https://www.w3.org/TR/microdata/#associating-names-with-items */ - $nodes = $xpath->query('//*[@itemscope and not(@itemprop)]'); + $nodes = $xpath->query('//*[@itemscope and (not(@itemprop) or @itemprop="mainEntity")]'); $nodes = iterator_to_array($nodes); return array_map(function(DOMNode $node) use ($xpath, $url) {