browser/navigate: _find_nextprev allow for space sep rel attribs

The _find_nextprev function of browser/navigate.py only checks to see if
the rell attribute equals 'prev', 'previous', or 'next'. This patch
changes this to check for a set intersection between {'prev',
'previous'} or {'next'} and the set of the space separated list of the
rel attribute.
This commit is contained in:
Tomasz Kramkowski 2017-02-18 19:04:25 +00:00
parent 0b94f2ed8c
commit 5b7090e402

View File

@ -70,11 +70,11 @@ def path_up(url, count):
def _find_prevnext(prev, elems):
"""Find a prev/next element in the given list of elements."""
# First check for <link rel="prev(ious)|next">
rel_values = ('prev', 'previous') if prev else ('next')
rel_values = {'prev', 'previous'} if prev else {'next'}
for e in elems:
if e.tag_name() not in ['link', 'a'] or 'rel' not in e:
continue
if e['rel'] in rel_values:
if set(e['rel'].split(' ')) & rel_values:
log.hints.debug("Found {!r} with rel={}".format(e, e['rel']))
return e