Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,10 @@ public function parseH(\DOMElement $e, $is_backcompat = false, $has_nested_mf =
'type' => $mfTypes,
'properties' => $return
);

if($e->getAttribute('id') !== '') {
$parsed['id'] = $e->getAttribute("id");
}

if($this->lang) {
// Language
Expand Down
39 changes: 39 additions & 0 deletions tests/Mf2/ParseHtmlIdTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Tests of the parsing methods within mf2\Parser
*/

namespace Mf2\Parser\Test;

use Mf2;
use Mf2\Parser;
use PHPUnit_Framework_TestCase;

/**
*
*/
class ParseHtmlIdTest extends PHPUnit_Framework_TestCase {
public function setUp() {
date_default_timezone_set('Europe/London');
}

/** as per https://github.com/microformats/microformats2-parsing/issues/44 */
public function testParserIdAttribute() {
$test = '<div class="h-feed" id="recentArticles"><h2 class="p-name">Recent Articles</h2><div class="hentry" id="article">Lorem Ipsum</div>
<div class="p-author h-card" id="theAuthor">Max Mustermann</div>
<div class="h-entry" id="">empty id should not be parsed</div>
<div class="h-entry" id="0">id=0 should work and not be treated false-y</div>
</div>';
$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']);
}
}