Skip to content

Commit 90e7ffc

Browse files
committed
Improved rel-bookmark parsing.
Updated tests to avoid implied u-url, test existing class attribute, and more complex rel-bookmark.
1 parent b27dc8d commit 90e7ffc

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

Mf2/Parser.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -770,17 +770,15 @@ public function parseH(\DOMElement $e) {
770770
$children = array();
771771
$dates = array();
772772

773-
foreach ( $this->xpath->query('.//a[@rel and @href]', $e) as $el )
773+
// each rel-bookmark with an href attribute
774+
foreach ( $this->xpath->query('.//a[contains(concat(" ",normalize-space(@rel)," ")," bookmark ") and @href]', $e) as $el )
774775
{
775-
// rel-bookmark found
776-
if ($el->getAttribute('rel') == 'bookmark') {
777-
$class = 'u-url';
778-
// rel-bookmark already has class-attribute; append current value
779-
if ($el->hasAttribute('class')) {
780-
$class .= ' ' . $el->getAttribute('class');
781-
}
782-
$el->setAttribute('class', $class);
776+
$class = 'u-url';
777+
// rel-bookmark already has class attribute; append current value
778+
if ($el->hasAttribute('class')) {
779+
$class .= ' ' . $el->getAttribute('class');
783780
}
781+
$el->setAttribute('class', $class);
784782
}
785783

786784
// Handle nested microformats (h-*)

tests/Mf2/ClassicMicroformatsTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,30 +191,30 @@ public function testRelBookmarkUrl() {
191191
192192
<article class="hentry">
193193
<span class="author">Lee Adama</span>
194-
<span class="entry-title">Jumping Rope for Weight Loss</span>
194+
<span class="entry-title"><a rel="bookmark" class="something" href="/2014/11/24/jump-rope">Jumping Rope for Weight Loss</a></span>
195195
<div class="entry-content">Some Content</div>
196-
<a rel="bookmark" href="/2014/11/24/jump-rope">Nov 24, 2014</a>
196+
Nov 24, 2014
197197
</article>
198198
199199
<article class="hentry">
200200
<span class="author">Kara Thrace</span>
201-
<span class="entry-title">Abstract Art in Graffiti</span>
201+
<span class="entry-title"><a rel="bookmark" class="" href="/2014/11/23/graffiti">Abstract Art in Graffiti</a></span>
202202
<div class="entry-content">More Content</div>
203-
<a rel="bookmark" href="/2014/11/23/graffiti">Nov 23, 2014</a>
203+
Nov 23, 2014
204204
</article>
205205
206206
<article class="hentry">
207207
<span class="author">President Roslyn</span>
208-
<span class="entry-title">Dreams of Earth</span>
208+
<span class="entry-title"><a rel="something bookmark" href="/2014/11/21/earth">Dreams of Earth</a></span>
209209
<div class="entry-content">Additional Content</div>
210-
<a rel="bookmark" href="/2014/11/21/earth">Nov 21, 2014</a>
210+
Nov 21, 2014
211211
</article>
212212
213213
<article class="hentry">
214214
<span class="author">Chief Tyrrol</span>
215-
<span class="entry-title">Organized Labor in Mining Colonies</span>
215+
<span class="entry-title"><a rel="something bookmark somethingelse" class="somethingelse" href="/2014/11/19/labor">Organized Labor in Mining Colonies</a></span>
216216
<div class="entry-content">More Content</div>
217-
<a rel="bookmark" href="/2014/11/19/labor">Nov 19, 2014</a>
217+
Nov 19, 2014
218218
</article>
219219
220220
</body>

0 commit comments

Comments
 (0)