Skip to content

Commit

Permalink
Merge pull request microformats#141 from aaronpk/issue-138
Browse files Browse the repository at this point in the history
parse u- and p- from link tags
  • Loading branch information
aaronpk authored Mar 4, 2018
2 parents 1ac6609 + 9f0141e commit 68b1715
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,12 +631,12 @@ public function parseP(\DOMElement $p) {
}

$this->resolveChildUrls($p);

if ($p->tagName == 'img' and $p->hasAttribute('alt')) {
$pValue = $p->getAttribute('alt');
} elseif ($p->tagName == 'area' and $p->hasAttribute('alt')) {
$pValue = $p->getAttribute('alt');
} elseif ($p->tagName == 'abbr' and $p->hasAttribute('title')) {
} elseif (($p->tagName == 'abbr' or $p->tagName == 'link') and $p->hasAttribute('title')) {
$pValue = $p->getAttribute('title');
} elseif (in_array($p->tagName, array('data', 'input')) and $p->hasAttribute('value')) {
$pValue = $p->getAttribute('value');
Expand All @@ -655,7 +655,7 @@ public function parseP(\DOMElement $p) {
* @todo make this adhere to value-class
*/
public function parseU(\DOMElement $u) {
if (($u->tagName == 'a' or $u->tagName == 'area') and $u->hasAttribute('href')) {
if (($u->tagName == 'a' or $u->tagName == 'area' or $u->tagName == 'link') and $u->hasAttribute('href')) {
$uValue = $u->getAttribute('href');
} elseif (in_array($u->tagName, array('img', 'audio', 'video', 'source')) and $u->hasAttribute('src')) {
$uValue = $u->getAttribute('src');
Expand All @@ -673,7 +673,7 @@ public function parseU(\DOMElement $u) {

if ($classTitle !== null) {
return $classTitle;
} elseif ($u->tagName == 'abbr' and $u->hasAttribute('title')) {
} elseif (($u->tagName == 'abbr' or $u->tagName == 'link') and $u->hasAttribute('title')) {
return $u->getAttribute('title');
} elseif (in_array($u->tagName, array('data', 'input')) and $u->hasAttribute('value')) {
return $u->getAttribute('value');
Expand Down
21 changes: 21 additions & 0 deletions tests/Mf2/ParseUTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,25 @@ public function testImpliedUWithEmptyHref() {
$this->assertEquals('http://example.com/', $output['items'][4]['children'][0]['properties']['url'][0]);
}

public function testValueFromLinkTag() {
$input = <<< END
<!doctype html>
<html class="h-entry">
<head>
<link rel="canonical" class="u-url p-name" href="https://example.com/" title="Example.com homepage">
</head>
<body></body>
</html>
END;

$parser = new Parser($input, 'https://example.com');
$output = $parser->parse();

$this->assertArrayHasKey('url', $output['items'][0]['properties']);
$this->assertEquals('https://example.com/', $output['items'][0]['properties']['url'][0]);

$this->assertArrayHasKey('name', $output['items'][0]['properties']);
$this->assertEquals('Example.com homepage', $output['items'][0]['properties']['name'][0]);
}

}

0 comments on commit 68b1715

Please sign in to comment.