diff --git a/Mf2/Parser.php b/Mf2/Parser.php index fe5590b..1686f5f 100644 --- a/Mf2/Parser.php +++ b/Mf2/Parser.php @@ -1141,6 +1141,10 @@ public function parseH(\DOMElement $e, $is_backcompat = false, $has_nested_mf = 'type' => $mfTypes, 'properties' => $return ); + + if(trim($e->getAttribute('id')) !== '') { + $parsed['id'] = trim($e->getAttribute("id")); + } if($this->lang) { // Language diff --git a/tests/Mf2/ParseHtmlIdTest.php b/tests/Mf2/ParseHtmlIdTest.php new file mode 100644 index 0000000..cb3f5b1 --- /dev/null +++ b/tests/Mf2/ParseHtmlIdTest.php @@ -0,0 +1,39 @@ +

Recent Articles

Lorem Ipsum
+
Max Mustermann
+
empty id should not be parsed
+
id=0 should work and not be treated false-y
+ '; + $result = Mf2\parse($test); + $this->assertArrayHasKey('id', $result['items'][0]); + $this->assertEquals('recentArticles', $result['items'][0]['id']); + $this->assertArrayHasKey('id', $result['items'][0]['children'][0]); + $this->assertEquals('article', $result['items'][0]['children'][0]['id']); + $this->assertArrayHasKey('id', $result['items'][0]['properties']['author'][0]); + $this->assertEquals('theAuthor', $result['items'][0]['properties']['author'][0]['id']); + $this->assertArrayNotHasKey('id', $result['items'][0]['children'][1]); + $this->assertArrayHasKey('id', $result['items'][0]['children'][2]); + $this->assertEquals('0', $result['items'][0]['children'][2]['id']); + } +} +